c++: Allow exporting const-qualified namespace-scope variables [PR99232]
By [basic.link] p3.2.1, a non-template non-volatile const-qualified variable is not necessarily internal linkage in a module declaration, and rather may have module linkage (or external linkage if it is exported, see p4.8). PR c++/99232 gcc/cp/ChangeLog: * decl.cc (grokvardecl): Don't mark variables attached to modules as internal. gcc/testsuite/ChangeLog: * g++.dg/modules/pr99232_a.C: New test. * g++.dg/modules/pr99232_b.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
This commit is contained in:
parent
aea337cf74
commit
726723c476
3 changed files with 27 additions and 1 deletions
|
@ -11006,7 +11006,8 @@ grokvardecl (tree type,
|
|||
&& (DECL_THIS_EXTERN (decl)
|
||||
|| ! constp
|
||||
|| volatilep
|
||||
|| inlinep));
|
||||
|| inlinep
|
||||
|| module_attach_p ()));
|
||||
TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
|
||||
}
|
||||
/* Not at top level, only `static' makes a static definition. */
|
||||
|
|
12
gcc/testsuite/g++.dg/modules/pr99232_a.C
Normal file
12
gcc/testsuite/g++.dg/modules/pr99232_a.C
Normal file
|
@ -0,0 +1,12 @@
|
|||
// PR c++/99232
|
||||
// { dg-additional-options "-fmodules-ts" }
|
||||
// { dg-module-cmi pr99232 }
|
||||
|
||||
export module pr99232;
|
||||
|
||||
export const double lambda{ 1.3 };
|
||||
export constexpr int a = 42;
|
||||
|
||||
export const double* get_lambda_addr() {
|
||||
return λ
|
||||
}
|
13
gcc/testsuite/g++.dg/modules/pr99232_b.C
Normal file
13
gcc/testsuite/g++.dg/modules/pr99232_b.C
Normal file
|
@ -0,0 +1,13 @@
|
|||
// PR c++/99232
|
||||
// { dg-module-do run }
|
||||
// { dg-additional-options "-fmodules-ts" }
|
||||
|
||||
import pr99232;
|
||||
|
||||
double foo() { return lambda * 2.0; }
|
||||
static_assert(a == 42);
|
||||
|
||||
int main() {
|
||||
if (&lambda != get_lambda_addr())
|
||||
__builtin_abort();
|
||||
}
|
Loading…
Add table
Reference in a new issue