https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124197
Bjorn Pagen <hello at bjornpagen dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hello at bjornpagen dot com
--- Comment #1 from Bjorn Pagen <hello at bjornpagen dot com> ---
I confirmed this behavior with GCC 16.1.0 and the C++26 reflection
implementation.
The reflection form also reports -Wshadow for the expansion variable:
#include <meta>
#include <cstddef>
#include <string_view>
enum class Compass { North, East, South, West };
consteval auto count() -> std::size_t {
auto result = std::size_t{0};
template for (constexpr auto enumerator
: std::define_static_array(
std::meta::enumerators_of(^^Compass))) {
if (!std::meta::identifier_of(enumerator).empty())
++result;
}
return result;
}
static_assert(count() == 4);
Command:
g++-16 -std=c++26 -freflection -Wshadow -Werror -c repro.cc
GCC reports four -Wshadow errors at the declaration of enumerator. It reports
one error for each expanded element.
The source contains one variable declaration and no nested declaration with the
same name. The warnings appear to come from the scopes that GCC creates for
expansion elements.
This behavior forces projects that use -Werror to disable -Wshadow for each
translation unit that contains an expansion statement.