From: Olivier Goffart Date: Thu, 16 Jun 2016 21:39:55 +0000 (+0000) Subject: Keep invalid functions as part of the AST X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21f60bb7d8ffb0440562d7649c01cc2735276901;p=clang Keep invalid functions as part of the AST Differential Revision: http://reviews.llvm.org/D19764 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272962 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 18185b07db..49a650e216 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -5100,10 +5100,9 @@ NamedDecl *Sema::HandleDeclarator(Scope *S, Declarator &D, if (!New) return nullptr; - // If this has an identifier and is not an invalid redeclaration or - // function template specialization, add it to the scope stack. - if (New->getDeclName() && AddToScope && - !(D.isRedeclaration() && New->isInvalidDecl())) { + // If this has an identifier and is not a function template specialization, + // add it to the scope stack. + if (New->getDeclName() && AddToScope) { // Only make a locally-scoped extern declaration visible if it is the first // declaration of this entity. Qualified lookup for such an entity should // only find this declaration if there is no visible declaration of it. diff --git a/test/Misc/ast-dump-invalid.cpp b/test/Misc/ast-dump-invalid.cpp index 7b02ba1113..bf260c040c 100644 --- a/test/Misc/ast-dump-invalid.cpp +++ b/test/Misc/ast-dump-invalid.cpp @@ -41,3 +41,24 @@ int g(int i) { // CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'int' // CHECK-NEXT: `-DeclRefExpr {{.*}} 'int' lvalue ParmVar {{.*}} 'i' 'int' + +namespace TestInvalidFunctionDecl { +struct Str { + double foo1(double, invalid_type); +}; +double Str::foo1(double, invalid_type) +{ return 45; } +} +// CHECK: NamespaceDecl {{.*}} <{{.*}}> {{.*}} TestInvalidFunctionDecl +// CHECK-NEXT: |-CXXRecordDecl {{.*}} line:46:8 struct Str definition +// CHECK-NEXT: | |-CXXRecordDecl {{.*}} col:8 implicit struct Str +// CHECK-NEXT: | `-CXXMethodDecl {{.*}} col:11 invalid foo1 'double (double, int)' +// CHECK-NEXT: | |-ParmVarDecl {{.*}} col:22 'double' +// CHECK-NEXT: | `-ParmVarDecl {{.*}} > col:36 invalid 'int' +// CHECK-NEXT: `-CXXMethodDecl {{.*}} parent {{.*}} line:49:13 invalid foo1 'double (double, int)' +// CHECK-NEXT: |-ParmVarDecl {{.*}} col:24 'double' +// CHECK-NEXT: |-ParmVarDecl {{.*}} > col:38 invalid 'int' +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: `-ReturnStmt {{.*}} +// CHECK-NEXT: `-ImplicitCastExpr {{.*}} 'double' +// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 45 diff --git a/test/Sema/predefined-function.c b/test/Sema/predefined-function.c index 1c40b6e8c2..aa7b28535b 100644 --- a/test/Sema/predefined-function.c +++ b/test/Sema/predefined-function.c @@ -4,14 +4,13 @@ char *funk(int format); enum Test {A=-1}; char *funk(enum Test x); -int eli(float b); // expected-note {{previous declaration is here}} \ -// expected-note{{passing argument to parameter 'b' here}} +int eli(float b); // expected-note {{previous declaration is here}} int b(int c) {return 1;} int foo(); int foo() { int eli(int (int)); // expected-error {{conflicting types for 'eli'}} - eli(b); // expected-error{{passing 'int (int)' to parameter of incompatible type 'float'}} + eli(b); return 0; }