diff options
| author | Douglas Gregor <dgregor@apple.com> | 2009-02-16 18:20:44 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2009-02-16 18:20:44 +0000 |
| commit | bcbf86399f16fcf02b278cf43a1aa83b522a9de3 (patch) | |
| tree | 4d9490ca9af14fa9e682969d865aeaa5e07cbc39 /clang/lib/Sema | |
| parent | a1c37501ed195d1e03b9871a09bdcf9d9a0559e5 (diff) | |
| download | bcm5719-llvm-bcbf86399f16fcf02b278cf43a1aa83b522a9de3.tar.gz bcm5719-llvm-bcbf86399f16fcf02b278cf43a1aa83b522a9de3.zip | |
When a function with a prototype is redeclared without a prototype,
merge the prototype into the redeclaration (and make a note in the
declaration). Fixes PR3588.
llvm-svn: 64641
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 3960a7d57c0..444f85e7739 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -593,7 +593,24 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, Decl *OldD) { // duplicate function decls like "void f(int); void f(enum X);" properly. if (!getLangOptions().CPlusPlus && Context.typesAreCompatible(OldQType, NewQType)) { + const FunctionType *NewFuncType = NewQType->getAsFunctionType(); + const FunctionTypeProto *OldProto = 0; + if (isa<FunctionTypeNoProto>(NewFuncType) && + (OldProto = OldQType->getAsFunctionTypeProto())) { + // The old declaration provided a function prototype, but the + // new declaration does not. Merge in the prototype. + llvm::SmallVector<QualType, 16> ParamTypes(OldProto->arg_type_begin(), + OldProto->arg_type_end()); + NewQType = Context.getFunctionType(NewFuncType->getResultType(), + &ParamTypes[0], ParamTypes.size(), + OldProto->isVariadic(), + OldProto->getTypeQuals()); + New->setType(NewQType); + New->setInheritedPrototype(); + } + MergeAttributes(New, Old); + return false; } |

