hokein created this revision. hokein added reviewers: sammccall, adamcz. Herald added a project: clang.
Previously, clang refused to build the AST nodes for them. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D76831 Files: clang/lib/AST/ComputeDependence.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaExpr.cpp clang/test/AST/ast-dump-expr-errors.cpp clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp clang/test/CXX/drs/dr3xx.cpp clang/test/CodeCompletion/error-covery.cpp clang/test/Modules/submodules-merge-defs.cpp clang/test/OpenMP/openmp_check.cpp clang/test/SemaCXX/block-call.cpp clang/test/SemaCXX/conversion-function.cpp clang/test/SemaCXX/cxx11-crashes.cpp clang/test/SemaCXX/cxx2a-explicit-bool.cpp clang/test/SemaCXX/for-range-examples.cpp
Index: clang/test/SemaCXX/for-range-examples.cpp =================================================================== --- clang/test/SemaCXX/for-range-examples.cpp +++ clang/test/SemaCXX/for-range-examples.cpp @@ -187,9 +187,9 @@ void f() { for (auto x : undeclared_identifier) // expected-error {{undeclared identifier}} for (auto y : x->foo) - y->bar(); + y->bar(); // expected-error {{member reference type 'auto' is not a pointer}} for (auto x : 123) // expected-error {{no viable 'begin'}} - x->foo(); + x->foo(); // expected-error {{member reference type 'auto' is not a pointer}} } } Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-explicit-bool.cpp +++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp @@ -124,7 +124,7 @@ A<true> && a6{ 0}; A<true> a7 = { 0}; // expected-error {{chosen constructor is explicit in copy-initialization}} -a0 = 0; +a0 = 0; // expected-error {{no viable overloaded '='}} a1 = { 0}; // expected-error {{no viable overloaded '='}} a2 = A<true>( 0); a3 = A<true>{ 0}; Index: clang/test/SemaCXX/cxx11-crashes.cpp =================================================================== --- clang/test/SemaCXX/cxx11-crashes.cpp +++ clang/test/SemaCXX/cxx11-crashes.cpp @@ -70,7 +70,7 @@ for (auto x : s) { // We used to attempt to evaluate the initializer of this variable, // and crash because it has an undeduced type. - const int &n(x); + const int &n(x); // expected-error {{reference to type 'const int' could not bind}} } } } Index: clang/test/SemaCXX/conversion-function.cpp =================================================================== --- clang/test/SemaCXX/conversion-function.cpp +++ clang/test/SemaCXX/conversion-function.cpp @@ -440,7 +440,7 @@ #endif } a; A::S s = a; // expected-error {{no viable conversion from 'struct A' to 'A::S'}} - A::E e = a; + A::E e = a; // expected-note {{'e' declared here}} bool k1 = e == A::e; // expected-error {{no member named 'e'}} bool k2 = e.n == 0; } Index: clang/test/SemaCXX/block-call.cpp =================================================================== --- clang/test/SemaCXX/block-call.cpp +++ clang/test/SemaCXX/block-call.cpp @@ -33,7 +33,7 @@ int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{cannot initialize a variable of type 'int (^)(int, char (^)(float))' with an lvalue of type}} IPCC2 = 0; - IPCC2 = 1; + IPCC2 = 1; // expected-error {{invalid block pointer conversion assigning}} int (^x)() = 0; int (^y)() = 3; // expected-error {{cannot initialize a variable of type 'int (^)()' with an rvalue of type 'int'}} int a = 1; Index: clang/test/OpenMP/openmp_check.cpp =================================================================== --- clang/test/OpenMP/openmp_check.cpp +++ clang/test/OpenMP/openmp_check.cpp @@ -28,5 +28,8 @@ } }; F(); +#if __cplusplus <= 199711L + // expected-error@-2 {{called object type 'auto' is not a function}} +#endif return a; } Index: clang/test/Modules/submodules-merge-defs.cpp =================================================================== --- clang/test/Modules/submodules-merge-defs.cpp +++ clang/test/Modules/submodules-merge-defs.cpp @@ -31,7 +31,9 @@ // expected-note@defs.h:4 +{{here}} // expected-note@defs.h:17 +{{here}} void pre_bfi(B b) { // expected-error +{{must be imported}} - b.f<int>(); + b.f<int>(); // expected-error {{member reference base type}} \ + expected-error {{expected '(' for function-style}} \ + expected-error {{expected expression}} } C_Base<1> pre_cb1; // expected-error +{{must be imported}} Index: clang/test/CodeCompletion/error-covery.cpp =================================================================== --- /dev/null +++ clang/test/CodeCompletion/error-covery.cpp @@ -0,0 +1,7 @@ +struct Foo { Foo(int); int abc; }; +void invalidDeclRefExpr() { + Foo foo; + foo.; + // RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:5:7 %s -o - | FileCheck %s + // CHECK: COMPLETION: abc +} Index: clang/test/CXX/drs/dr3xx.cpp =================================================================== --- clang/test/CXX/drs/dr3xx.cpp +++ clang/test/CXX/drs/dr3xx.cpp @@ -429,8 +429,8 @@ namespace dr331 { // dr331: yes struct A { - A(volatile A&); // expected-note {{candidate}} - } const a, b(a); // expected-error {{no matching constructor}} + A(volatile A&); // expected-note 2{{candidate}} + } const a, b(a); // expected-error 2{{no matching constructor}} } namespace dr332 { // dr332: dup 577 Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp =================================================================== --- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp +++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp @@ -93,7 +93,7 @@ void f(X *x) { auto value = x->method; // expected-error {{reference to non-static member function must be called}} - if (value) { } + if (value) { } // expected-error {{value of type 'auto' is not contextually convertible to 'bool'}} auto funcptr = &g<int>; int (*funcptr2)(int) = funcptr; Index: clang/test/AST/ast-dump-expr-errors.cpp =================================================================== --- clang/test/AST/ast-dump-expr-errors.cpp +++ clang/test/AST/ast-dump-expr-errors.cpp @@ -42,5 +42,16 @@ // FIXME: store initializer even when 'auto' could not be deduced. // Expressions with errors currently do not keep initializers around. -// CHECK: `-VarDecl {{.*}} invalid e 'auto' +// CHECK: |-VarDecl {{.*}} invalid e 'auto' auto e = bar(); + +// CHECK: FunctionDecl {{.*}} +// CHECK-NEXT: `-CompoundStmt {{.*}} +// CHECK-NEXT: |-DeclStmt {{.*}} +// CHECK-NEXT: | `-VarDecl {{.*}} invalid foo 'Foo' +// CHECK-NEXT: `-DeclRefExpr {{.*}} 'Foo' contains-errors +struct Foo { Foo(int); }; +void invalidDeclRefExpr() { + Foo foo; + foo; +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -3005,8 +3005,9 @@ /// as an expression. This is only actually called for lookups that /// were not overloaded, and it doesn't promise that the declaration /// will in fact be used. -static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D) { - if (D->isInvalidDecl()) +static bool CheckDeclInExpr(Sema &S, SourceLocation Loc, NamedDecl *D, + bool AcceptInvalidDecl) { + if (!AcceptInvalidDecl && D->isInvalidDecl()) return true; if (isa<TypedefNameDecl>(D)) { @@ -3052,7 +3053,8 @@ // result, because in the overloaded case the results can only be // functions and function templates. if (R.isSingleResult() && !ShouldLookupResultBeMultiVersionOverload(R) && - CheckDeclInExpr(*this, R.getNameLoc(), R.getFoundDecl())) + CheckDeclInExpr(*this, R.getNameLoc(), R.getFoundDecl(), + AcceptInvalidDecl)) return ExprError(); // Otherwise, just build an unresolved lookup expression. Suppress @@ -3084,7 +3086,7 @@ "Cannot refer unambiguously to a function template"); SourceLocation Loc = NameInfo.getLoc(); - if (CheckDeclInExpr(*this, Loc, D)) + if (CheckDeclInExpr(*this, Loc, D, AcceptInvalidDecl)) return ExprError(); if (TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) { @@ -3159,7 +3161,6 @@ case Decl::ObjCIvar: assert(getLangOpts().CPlusPlus && "building reference to field in C?"); - // These can't have reference type in well-formed programs, but // for internal consistency we do this anyway. type = type.getNonReferenceType(); Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -1233,7 +1233,8 @@ Result.resolveKind(); bool ADL = UseArgumentDependentLookup(SS, Result, NextToken.is(tok::l_paren)); - return BuildDeclarationNameExpr(SS, Result, ADL); + return BuildDeclarationNameExpr(SS, Result, ADL, + Context.getLangOpts().RecoveryAST); } Sema::TemplateNameKindForDiagnostics Index: clang/lib/AST/ComputeDependence.cpp =================================================================== --- clang/lib/AST/ComputeDependence.cpp +++ clang/lib/AST/ComputeDependence.cpp @@ -383,6 +383,8 @@ if (Decl->isParameterPack()) Deps |= ExprDependence::UnexpandedPack; + if (Decl->isInvalidDecl()) + Deps |= ExprDependence::Error; Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error; // (TD) C++ [temp.dep.expr]p3:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits