Mark declarations as referenced by a default argument in a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 11 Jun 2019 23:51:46 +0000 (23:51 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 11 Jun 2019 23:51:46 +0000 (23:51 +0000)
potentially-evaluated context.

This applies even if the use of the default argument is within an
unevaluated context.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363113 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaTemplate/default-arguments.cpp

index ed39278b1adbd3c8c064743625b2885e3bba76cb..d444a35be863d51548c2ae0d996fd72efd6fedee 100644 (file)
@@ -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;
index b5b042c64a71ea6c4476c07f743dcd7bf2de4edf..882b279de1d08f39fe958205fadcf8256957b775 100644 (file)
@@ -223,3 +223,9 @@ namespace friends {
     X<int> *p;
   }
 }
+
+namespace unevaluated {
+  int a;
+  template<int = 0> int f(int = a); // expected-warning 0-1{{extension}}
+  int k = sizeof(f());
+}