diff options
author | Jason Merrill <jason@redhat.com> | 2021-02-08 17:16:14 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-02-08 20:52:11 -0500 |
commit | 57d705da0b98f5d398c4b8f9bd76fe8ad98e13bc (patch) | |
tree | 1b36fb8df77b80cd451aa0bfc19394173e5368db /gcc | |
parent | bdbca69e0720fa9062fe71782235141f629ae006 (diff) | |
download | gcc-57d705da0b98f5d398c4b8f9bd76fe8ad98e13bc.zip gcc-57d705da0b98f5d398c4b8f9bd76fe8ad98e13bc.tar.gz gcc-57d705da0b98f5d398c4b8f9bd76fe8ad98e13bc.tar.bz2 |
c++: consteval and explicit instantiation [PR96905]
Normally, an explicit instantiation means we want to write out the
instantiation. But not for a consteval function.
gcc/cp/ChangeLog:
PR c++/96905
* pt.c (mark_decl_instantiated): Exit early if consteval.
gcc/testsuite/ChangeLog:
PR c++/96905
* g++.dg/cpp2a/consteval-expinst1.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/pt.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/consteval-expinst1.C | 20 |
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 3605b67..f73deb3 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24154,6 +24154,11 @@ mark_decl_instantiated (tree result, int extern_p) if (TREE_ASM_WRITTEN (result)) return; + /* consteval functions are never emitted. */ + if (TREE_CODE (result) == FUNCTION_DECL + && DECL_IMMEDIATE_FUNCTION_P (result)) + return; + /* For anonymous namespace we don't need to do anything. */ if (decl_anon_ns_mem_p (result)) { diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-expinst1.C b/gcc/testsuite/g++.dg/cpp2a/consteval-expinst1.C new file mode 100644 index 0000000..01452dd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/consteval-expinst1.C @@ -0,0 +1,20 @@ +// PR c++/96905 +// { dg-do compile { target c++20 } } + +template<typename Rep> +struct duration +{ + static consteval int + gcd(int m, int n) noexcept + { + while (m != 0 && n != 0) + { + int rem = m % n; + m = n; + n = rem; + } + return m + n; + } +}; + +template class duration<int>; |