c++/modules: Allow imported references in constant expressions
Currently the streaming code uses TREE_CONSTANT to determine whether an entity will have a definition that is interesting to stream out. This is not sufficient, however; we also need to write the definition of references, since although not TREE_CONSTANT they can still be usable in constant expressions. As such this patch uses the existing decl_maybe_constant_var function which correctly handles this case. gcc/cp/ChangeLog: * module.cc (has_definition): Use decl_maybe_constant_var instead of TREE_CONSTANT. gcc/testsuite/ChangeLog: * g++.dg/modules/cexpr-5_a.C: New test. * g++.dg/modules/cexpr-5_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
This commit is contained in:
parent
d0762e93ce
commit
1a0b33ebc5
3 changed files with 23 additions and 1 deletions
|
@ -11829,7 +11829,7 @@ has_definition (tree decl)
|
|||
since there's no TU to emit them in otherwise. */
|
||||
return true;
|
||||
|
||||
if (!TREE_CONSTANT (decl))
|
||||
if (!decl_maybe_constant_var_p (decl))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
13
gcc/testsuite/g++.dg/modules/cexpr-5_a.C
Normal file
13
gcc/testsuite/g++.dg/modules/cexpr-5_a.C
Normal file
|
@ -0,0 +1,13 @@
|
|||
// { dg-additional-options "-fmodules-ts" }
|
||||
// { dg-module-cmi M }
|
||||
|
||||
export module M;
|
||||
|
||||
int x = 123;
|
||||
void f() {}
|
||||
|
||||
int& xr = x;
|
||||
auto& fr = f;
|
||||
|
||||
constexpr int& cxr = xr;
|
||||
constexpr auto& cfr = fr;
|
9
gcc/testsuite/g++.dg/modules/cexpr-5_b.C
Normal file
9
gcc/testsuite/g++.dg/modules/cexpr-5_b.C
Normal file
|
@ -0,0 +1,9 @@
|
|||
// { dg-additional-options "-fmodules-ts" }
|
||||
|
||||
module M;
|
||||
|
||||
constexpr auto& use_xr = xr;
|
||||
constexpr auto& use_fr = fr;
|
||||
|
||||
static_assert(&cxr == &use_xr);
|
||||
static_assert(&cfr == &use_fr);
|
Loading…
Add table
Reference in a new issue