Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -166,6 +166,8 @@ - Allow use of an elaborated type specifier as a ``_Generic`` selection association in C++ mode. This fixes `Issue 55562 `_. +- Clang will allow calling a ``consteval`` function in a default argument. This + fixes `Issue 48230 `_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Index: clang/lib/AST/Decl.cpp =================================================================== --- clang/lib/AST/Decl.cpp +++ clang/lib/AST/Decl.cpp @@ -2867,7 +2867,8 @@ Expr *Arg = getInit(); if (auto *E = dyn_cast_or_null(Arg)) - return E->getSubExpr(); + if (!isa(E)) + return E->getSubExpr(); return Arg; } Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -19611,6 +19611,12 @@ Inherited::Visit(E); } + void VisitConstantExpr(ConstantExpr *E) { + // Don't mark declarations within a ConstantExpression, as this expression + // will be evaluated and folded to a value. + return; + } + void VisitDeclRefExpr(DeclRefExpr *E) { // If we were asked not to visit local variables, don't. if (SkipLocalVariables) { Index: clang/test/SemaCXX/cxx2a-consteval.cpp =================================================================== --- clang/test/SemaCXX/cxx2a-consteval.cpp +++ clang/test/SemaCXX/cxx2a-consteval.cpp @@ -651,6 +651,27 @@ } // namespace value_dependent +namespace default_argument { + +// Previously calls of consteval functions in default arguments were rejected. +// Now we show that we don't reject such calls. +consteval int foo() { return 1; } +consteval int bar(int i = foo()) { return i * i; } + +struct Test1 { + Test1(int i = bar(13)) {} + void v(int i = bar(13) * 2 + bar(15)) {} +}; +Test1 t1; + +struct Test2 { + constexpr Test2(int i = bar()) {} + constexpr void v(int i = bar(bar(bar(foo())))) {} +}; +Test2 t2; + +} // namespace default_argument + namespace PR50779 { struct derp { int b = 0;