]> gcc.gnu.org Git - gcc.git/commit
c++: wrong error with static constexpr var in tmpl [PR109876]
authorMarek Polacek <polacek@redhat.com>
Thu, 25 May 2023 22:54:18 +0000 (18:54 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 12 Dec 2023 00:30:18 +0000 (19:30 -0500)
commit08f4496aa619f9b0e8dbb459452dd96edb870236
tree0a756b4f865f7f70506cb7dd31ada8e85c75b38d
parent7308b4d57f08c8fc9c6cb877d0cf2657b9b4805f
c++: wrong error with static constexpr var in tmpl [PR109876]

Since r8-509, we'll no longer create a static temporary var for
the initializer '{ 1, 2 }' for num in the attached test because
the code in finish_compound_literal is now guarded by
'&& fcl_context == fcl_c99' but it's fcl_functional here.  This
causes us to reject num as non-constant when evaluating it in
a template.

Jason's idea was to treat num as value-dependent even though it
actually isn't.  This patch implements that suggestion.

We weren't marking objects whose type is an empty class type
constant.  This patch changes that so that v_d_e_p doesn't need
to check is_really_empty_class.

Co-authored-by: Jason Merrill <jason@redhat.com>
PR c++/109876

gcc/cp/ChangeLog:

* decl.cc (cp_finish_decl): Set TREE_CONSTANT when initializing
an object of empty class type.
* pt.cc (value_dependent_expression_p) <case VAR_DECL>: Treat a
constexpr-declared non-constant variable as value-dependent.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/constexpr-template12.C: New test.
* g++.dg/cpp1z/constexpr-template1.C: New test.
* g++.dg/cpp1z/constexpr-template2.C: New test.

(cherry picked from commit b5138df96a93d3b5070c88b8617eabd38cb24ab6)
gcc/cp/decl.cc
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp0x/constexpr-template12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/constexpr-template1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/constexpr-template2.C [new file with mode: 0644]
This page took 0.06905 seconds and 6 git commands to generate.