https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80780
--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:ba3d8dffcc1c23b30370ab24fc20d09cff005d7b commit r11-5685-gba3d8dffcc1c23b30370ab24fc20d09cff005d7b Author: Jakub Jelinek <ja...@redhat.com> Date: Thu Dec 3 00:25:51 2020 +0100 c++: Implement LWG3396 Clarify point of reference for source_location::current() [PR80780, PR93093] While std::source_location::current () is static consteval source_location current() noexcept; in the standard, it also says with LWG3396: "Any call to current that appears as a default member initializer ([class.mem]), or as a subexpression thereof, should correspond to the location of the constructor definition or aggregate initialization that uses the default member initializer. Any call to current that appears as a default argument ([dcl.fct.default]), or as a subexpression thereof, should correspond to the location of the invocation of the function that uses the default argument ([expr.call])." so it must work as compiler magic rather than normal immediate functions, in particular we need to defer its evaluation when parsing default arguments or nsdmis. This patch actually defers evaluation of all the calls to std::source_location::current () until genericization (or constant expression evaluation when called from constant expression contexts). I had to change constexpr.c too so that it temporarily adjusts current_function_decl from the constexpr evaluation context, but we do the same already from __builtin_FUNCTION (). 2020-12-03 Jakub Jelinek <ja...@redhat.com> PR c++/80780 PR c++/93093 * cp-tree.h (source_location_current_p): Declare. * tree.c (source_location_current_p): New function. * call.c (immediate_invocation_p): New function. (build_over_call): Use it to resolve LWG3396. * constexpr.c (cxx_eval_builtin_function_call): Temporarily set current_function_decl from ctx->call->fundef->decl if any. * cp-gimplify.c (cp_genericize_r) <case CALL_EXPR>: Fold calls to immediate function std::source_location::current (). * g++.dg/cpp2a/srcloc15.C: New test. * g++.dg/cpp2a/srcloc16.C: New test. * g++.dg/cpp2a/srcloc17.C: New test. * g++.dg/cpp2a/srcloc18.C: New test.