From: Douglas Gregor Date: Tue, 19 Oct 2010 17:17:35 +0000 (+0000) Subject: When marking declarations referenced within an expression (e.g., X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=102ff97bc55ba9f925a100671d49e49b3c5f7129;p=clang When marking declarations referenced within an expression (e.g., within a default argument), recurse into default arguments. Fixes PR8401, a regression I introduced in r113700 while refactoring our handling of "used" declarations in default arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116817 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 031337d6fe..f98aefcd56 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8019,6 +8019,10 @@ namespace { void VisitBlockDeclRefExpr(BlockDeclRefExpr *E) { S.MarkDeclarationReferenced(E->getLocation(), E->getDecl()); } + + void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { + Visit(E->getExpr()); + } }; } diff --git a/test/SemaTemplate/default-expr-arguments.cpp b/test/SemaTemplate/default-expr-arguments.cpp index eff59a84e3..8d54926b96 100644 --- a/test/SemaTemplate/default-expr-arguments.cpp +++ b/test/SemaTemplate/default-expr-arguments.cpp @@ -274,3 +274,21 @@ namespace rdar8427926 { x->g(); } } + +namespace PR8401 { + template + struct A { + A() { T* x = 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} + }; + + template + struct B { + B(const A& a = A()); // expected-note{{in instantiation of}} + }; + + void f(B b = B()); + + void g() { + f(); + } +}