Function pointer variables

Hi,

clang blows up with the following program:
void (*f)(void);
void (*f)() = 0;

But gcc compiles happily. Also, in the draft for the standard ( http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf ), it is said that (section 6.9.1 - Function definitions):

typedef int F(void); //type F is ‘‘function with no parameters
                       // returning int’’
// ...
int g() { /* ... */ } //RIGHT: g has type compatible with F

So I'm assuming it's a bug in clang.

Also, is there a way to make clang just blow up when there's an error like this so one can see easilly where it blew up and inspect the code? (I'm aware that often it is not there that the mistake is, but it's a starting point)

Keep up the good work :slight_smile:

  - Filipe Cabecinhas

Hi Filipe,

Are you running a "Debug" build? If so, then the assertions should be on. You can also look at the source code to see where the message is being output (each diagnostic has it's own enum name; look at Diagnostics.def for them). You can then set a breakpoint at that place in the debugger and see what's going on.

-bw

Thanks, that's what I just did and I found it... Now to just try to understand clang's internals :slight_smile:

   - Filipe Cabecinhas

Hi Filipe,

Feel free to file a bugzilla report with your test case that blows up. If you file a report, please make sure you include the exact command line you used to invoke clang, as well as the SVN revision number (if you have it). If you manage to diagnose more what is going wrong you can add it as comments to the bugzilla report, or even submit a patch with a fix. Putting it in bugzilla ensures that it will eventually get fixed.

Ted

Done: http://llvm.org/bugs/show_bug.cgi?id=2502

   - Filipe Cabecinhas

Hi,

I reported the bug at bugzilla and, with Eli Friedman, we narrowed it down to MergeVarDecl.

I changed the "OldCType != NewCType" to a call to typesAreCompatible(). I kept the call to areEquivalentArrayTypes but, as Eli pointed out, maybe it's doing checks that are already done in typesAreCompatible().

   - Filipe Cabecinhas

clang-functionTypes.diff (703 Bytes)