Repository navigation
Deferred instantiation constant-evaluates a constexpr function template that is still being instantiated #621
gwllx
started this conversation in
Issue Triage - Compilation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Issue Summary
Valid C++ is rejected with
error #28: expression must have a constant valuebecause deferred instantiation attempts to constant-evaluate a constexpr function template that is itself still being instantiated and therefore does not yet have a body.The issue was found when compiling the libstdc++15 implementation of
std::variant, where clang and gcc accept it.Reproducing Source Code
https://godbolt.org/z/hnf95fx5e
For reference, here is a slightly larger reproducer that keeps the
std::variantshape: https://godbolt.org/z/Eq87Mhhv6.Command-line Options
cpfe --c++20
Type of Issue
[Front End] This code SHOULD compile with these options.
Additional Details
While parsing the default arguments of
S,defer_instantiationsis set, so the request for~B<int>()from= {}is appended todeferred_instantiations. The body ofS::gis parsed afterwards, withdefer_instantiationsunset. This instantiatesf<int>. When the class instantiation ofA<int>insidef<int>finishes, it callsprocess_deferred_instantiation_requests, which instantiates~B<int>(). That now constant-evaluatesf()` before it has a body.Reproducing (Standard) Configuration(s)
No response
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.All reactions