diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-08-07 19:08:07 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-08-07 19:08:07 +0200 |
commit | 82cd63a63eaa61a4ed5c4029a1869be7446ecb3c (patch) | |
tree | ea6bc7b14bcb893c669a7e7d704d1a5dfd22a29f /gcc | |
parent | 2c6174402ea315ecf618cfcba741e8cb18bc5282 (diff) | |
download | gcc-82cd63a63eaa61a4ed5c4029a1869be7446ecb3c.zip gcc-82cd63a63eaa61a4ed5c4029a1869be7446ecb3c.tar.gz gcc-82cd63a63eaa61a4ed5c4029a1869be7446ecb3c.tar.bz2 |
c++: Implement CWG2387 - Linkage of const-qualified variable template [PR109126]
The following patch attempts to implement DR2387 by making variable
templates including their specialization TREE_PUBLIC when at file
scope and they don't have static storage class.
2024-08-07 Jakub Jelinek <jakub@redhat.com>
PR c++/109126
* decl.cc (grokvardecl): Implement CWG 2387 - Linkage of
const-qualified variable template. Set TREE_PUBLIC on variable
templates with const qualified types unless static is present.
* g++.dg/DRs/dr2387.C: New test.
* g++.dg/DRs/dr2387-aux.cc: New file.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/decl.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/DRs/dr2387-aux.cc | 25 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/DRs/dr2387.C | 22 |
3 files changed, 49 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 86d2bfa..a468bfd 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -11225,6 +11225,8 @@ grokvardecl (tree type, || ! constp || volatilep || inlinep + || in_template_context + || processing_specialization || module_attach_p ())); TREE_STATIC (decl) = ! DECL_EXTERNAL (decl); } diff --git a/gcc/testsuite/g++.dg/DRs/dr2387-aux.cc b/gcc/testsuite/g++.dg/DRs/dr2387-aux.cc new file mode 100644 index 0000000..7a78ac2 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2387-aux.cc @@ -0,0 +1,25 @@ +// DR 2387 + +template <int N> +extern const int a; +template <int N> +static const int b = N; +template <int N> +extern const int c; +template <int N> +extern const volatile int d; +template <int N> +extern const int e; +extern const int *pa, *pb, *pc, *pe; +extern const volatile int *pd; + +int +main () +{ + if (pa != &a <42> + || pb == &b <42> + || pc != &c <42> + || pd != &d <42> + || pe != &e <43>) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/DRs/dr2387.C b/gcc/testsuite/g++.dg/DRs/dr2387.C new file mode 100644 index 0000000..afbe618 --- /dev/null +++ b/gcc/testsuite/g++.dg/DRs/dr2387.C @@ -0,0 +1,22 @@ +// DR 2387 +// { dg-do run { target c++14 } } +// { dg-additional-sources "dr2387-aux.cc" } + +template <int N> +const int a = N; +template <int N> +static const int b = N; +template <int N> +extern const int c = N; +template <int N> +const volatile int d = N; +template <int N> +const int e = N; +template <> +const int e <43> = 44; + +const int *pa = &a <42>; +const int *pb = &b <42>; +const int *pc = &c <42>; +const volatile int *pd = &d <42>; +const int *pe = &e <43>; |