[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2020-12-08 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #8 from Jakub Jelinek  ---
Fixed for GCC 11.

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2020-12-02 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

--- Comment #7 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:ba3d8dffcc1c23b30370ab24fc20d09cff005d7b

commit r11-5685-gba3d8dffcc1c23b30370ab24fc20d09cff005d7b
Author: Jakub Jelinek 
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  

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) : 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.

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2020-02-13 Thread jason at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

--- Comment #6 from Jason Merrill  ---
This is https://github.com/cplusplus/nbballot/issues/167

In CWG today we decided that since this is all compiler magic anyway, we can be
a bit more magical to get around this problematic interaction with consteval.

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2020-02-13 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

--- Comment #5 from Jakub Jelinek  ---
Jason, do you think the current spec is clear enough on when the consteval
evaluation of default arguments ought to happen (and does our implementation
match that), or does it need clarification?

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2020-02-13 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2020-02-13
 Ever confirmed|0   |1

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2020-01-02 Thread phdofthehouse at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

--- Comment #4 from JeanHeyd Meneide  ---
I changed the library test cases, but maybe there needs to be something that
helps the library developers tag a constant evaluation function as something
that should be ran later / deferred. I don't have any good ideas, just
spitballing.

Either way, the new patch passes by not testing for some of the cases similar
to what's in the Standard passage in [support.srcloc]:
https://gcc.gnu.org/ml/gcc-patches/2020-01/msg00036.html

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2019-12-31 Thread phdofthehouse at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

--- Comment #3 from JeanHeyd Meneide  ---
I guess we just throw out a handful of those test cases, then. It's not like
the Standard is really impactful here, since most of Source Location's
specification is "should...", which is encouragement and not requirement.

Maybe this can be revisited later.

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2019-12-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

--- Comment #2 from Jakub Jelinek  ---
What this boils down to is e.g. whether
consteval int foo (int i) { if (i) throw 1; return 0; }
void bar (int x = foo (0));
void baz (int x = foo (1));
void qux () { bar (0); bar (); baz (0); }
needs to be rejected (it is rejected by g++) or not, if it is invalid, no
diagnostics required, or if it would be invalid only if there would be a baz
(); call somewhere.
If the above testcase is invalid, and default arguments to non-immediate
functions need to be evaluated if they contain calls to immediate functions,
then I don't see how your #c0 testcase can expect what it expects, because
source_location::current() will be evaluated not when you expect it to and by
the time something else invokes the constructor or function, the default
argument will already have a constant value.

[Bug c++/93093] __builtin_source_location reports values for default arguments not aligned with the Standard

2019-12-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93093

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||jason at gcc dot gnu.org,
   ||redi at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek  ---
I think this boils down when should calls to immediate functions be evaluated
in default arguments.
What GCC implements right now is that calls to consteval functions in default
arguments are deferred until later if the default argument is for an immediate
function (and is then evaluated later when call to such consteval function is
seen outside of immediate context), but otherwise is evaluated immediately
while parsing the default argument.
In the testcase, as s::s(source_location) or void f(source_location) aren't
immediate, the constexpr evaluation is performed on the default argument right
away.
Now, if that is not how it should be treated, please point me at where the C++
standard says so.