]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Don't accept multiple enum definitions within template class [PR115806]
authorSimon Martin <simon@nasilyan.com>
Thu, 8 Aug 2024 12:59:49 +0000 (14:59 +0200)
committerSimon Martin <simon@nasilyan.com>
Fri, 9 Aug 2024 15:15:43 +0000 (17:15 +0200)
commit786ebbd6058540b2110da16a693f0c582c11413c
tree2b8b054fc1985983924c083df92589040872c66d
parent180ede3543e98ade8f809afe8be5af0eeaeff7bb
c++: Don't accept multiple enum definitions within template class [PR115806]

We have been accepting the following invalid code since revision 557831a91df

=== cut here ===
template <typename T> struct S {
  enum E { a };
  enum E { b };
};
S<int> s;
=== cut here ===

The problem is that start_enum will set OPAQUE_ENUM_P to true even if it
retrieves an existing definition for the enum, which causes the redefinition
check in cp_parser_enum_specifier to be bypassed.

This patch only sets OPAQUE_ENUM_P and ENUM_FIXED_UNDERLYING_TYPE_P when
actually pushing a new tag for the enum.

PR c++/115806

gcc/cp/ChangeLog:

* decl.cc (start_enum): Only set OPAQUE_ENUM_P and
ENUM_FIXED_UNDERLYING_TYPE_P when pushing a new tag.

gcc/testsuite/ChangeLog:

* g++.dg/parse/enum15.C: New test.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/parse/enum15.C [new file with mode: 0644]