[PATCH] D25001: [Module] Merge function prototype with a non-prototype function declaration

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 15:02:52 PDT 2016


rsmith added a comment.

I'm concerned that name lookup will find an inappropriate declaration after this merging. If we have two visible declarations of a function in the same scope, and one has a prototype but the other does not, the user should be able to rely on the prototype being used. `isPreferredLookupResult` in SemaLookup.cpp picks the most recent declaration in an attempt to handle this, but that won't do the right thing here, so you should also teach it to prefer a prototyped function over an unprototyped one.

You should be able to test for this case by trying to pass a pointer to the wrong type to `func1`. (You may need a different testcase that provides the prototype in the .c file and the declaration without prototype in the header in order to hit this, depending on which result name lookup ends up preferring.)



================
Comment at: lib/Serialization/ASTReaderDecl.cpp:2715
     return (FuncX->getLinkageInternal() == FuncY->getLinkageInternal()) &&
       FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType());
   }
----------------
Instead of your change, can we change this to use `typesAreCompatible` instead of `hasSameType`?


https://reviews.llvm.org/D25001





More information about the cfe-commits mailing list