From 7f61d441789c7b1f7c96d7672a176eb996ecb73f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 11 Jun 2019 23:51:46 +0000 Subject: [PATCH] Mark declarations as referenced by a default argument in a potentially-evaluated context. This applies even if the use of the default argument is within an unevaluated context. llvm-svn: 363113 --- clang/lib/Sema/SemaExpr.cpp | 2 ++ clang/test/SemaTemplate/default-arguments.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index ed39278b1adb..d444a35be863 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4855,6 +4855,8 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, // We already type-checked the argument, so we know it works. // Just mark all of the declarations in this potentially-evaluated expression // as being "referenced". + EnterExpressionEvaluationContext EvalContext( + *this, ExpressionEvaluationContext::PotentiallyEvaluated, Param); MarkDeclarationsReferencedInExpr(Param->getDefaultArg(), /*SkipLocalVariables=*/true); return false; diff --git a/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp index b5b042c64a71..882b279de1d0 100644 --- a/clang/test/SemaTemplate/default-arguments.cpp +++ b/clang/test/SemaTemplate/default-arguments.cpp @@ -223,3 +223,9 @@ namespace friends { X *p; } } + +namespace unevaluated { + int a; + template int f(int = a); // expected-warning 0-1{{extension}} + int k = sizeof(f()); +}