This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11284] Bad code generation with "warning: the address ... will always be `true'"


giovannibajo at libero dot it changed:

           What    |Removed                     |Added
                 CC|                            |,
                   |                            |

------- Additional Comments From giovannibajo at libero dot it  2003-06-22 16:53 -------
The warning is not a bug. The reduced snippet is:

struct Bar
    Bar(bool );

struct Foo

int main(void)
    Bar a(Foo());
    Bar b(a);

    return 0;
pr11284.cpp: In function `int main()':
pr11284.cpp:12: warning: the address of `Bar a(Foo (*)())', will always be 

The problem is that the original submitter thinks that the first line in main() 
is creating an object of type Bar called "a". Instead, the line is declaring a 
function called "a", which returns an object of type Bar, and takes as argument 
a pointer to a function of type "Foo (*)()" (no parameters, returns a Foo). In 
other words, it's a function declaration.

So, when the second line is parsed (which is really an object definition), the 
compiler initializes Bar with function "a". While converting the function 
pointer to a boolean type, it emits a warning to notify the user that the 
result will always be true (a function pointer that comes from using a function 
name can never be NULL).

I keep the bug open because the testcase ICEs GCC 3.3. If someone wants to 
reduce it, we can check if it's a dupe.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]