Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't GCC show any errors on an anonymous variable?

I read this question that explains how anonymous variables are invalid in C++.

But the following program compiles without any warning or errors on GCC 7.2 (even with -Wall) - demo:

int main() {
    int (*); // anonymous variable?
}

Here, this is apparently also an integer type anonymous variable. So, why GCC does not show any errors or warnings? Is this a GCC bug?

like image 386
Jayesh Avatar asked Oct 31 '17 07:10

Jayesh


People also ask

How do I enable warnings in GCC?

GCC 4.3+ now has -Q --help=warnings , and you can even specify --help=warnings,C to just print out the C related warnings.

How does GCC treat warning errors?

You can use the -Werror compiler flag to turn all or some warnings into errors. Show activity on this post. You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.

Which flags would you pass to your C++ compiler so it warns you about uninitialized variables?

Warn about uninitialized variables that are initialized with themselves. Note this option can only be used with the -Wuninitialized option. This warning is enabled by -Wall in C++. This option controls warnings when a declaration does not specify a type.

Which GCC flag is used to enable all compiler warnings?

gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.


Video Answer


1 Answers

There have been bugs recorded with gcc and how it detects variables for example I was using it to compile a simple program and it gave an error saying variable may be uninitialized when it have been. It is just a bug in the compiler. For example see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55985

like image 118
Oliver Strong Avatar answered Oct 05 '22 04:10

Oliver Strong