https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115429
Bug ID: 115429 Summary: requires clause wrongly accepts unqualified access to inherited static members Product: gcc Version: 14.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: eratchias at gmail dot com Target Milestone: --- Created attachment 58402 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58402&action=edit Preprocessed minimal example If we have: - a templated class `B` with a non-private data member constexpr static bool `con` - a templated class `A` that is derived from `B` such that it's base isn't fully instantiated(It's template parameters depend on template parameters of `A`) Then simple requires clauses(not enclosed in parenthesis) will have unqualified access to `con`. This should normally result in a compile error as it does if unqualified `con` is used anywhere else in class `A`. Additionally the access it provides doesn't even work the same way as the correct way of accessing it with `A::con` as it is assumed to not change between different instantiations of `A`. Extended example: #include <iostream> template <bool x> class B { public: constexpr static bool con = x; }; template<bool x = true> class A: public B<x> { public: // Option 1: Incorrectly accepted bool c() requires con { return true; } // Option 2: Correct behaviour // Doesn't compile: con was not declared // bool c() requires (con) { // return true; // } }; int main() { A<> a{}; std::cout << a.c() << std::endl; // 1 std::cout << a.con << std::endl; // 1 // Here the method is chosen based on B<true> not B<false> A<false> aa{}; std::cout << aa.c() << std::endl; // 1 std::cout << aa.con << std::endl; // 0 } output of gcc -v: Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 14.1.1 20240522 (GCC) The file is compiled with: g++ -std=c++20 example-no-iostream.cpp Code compiles without any warnings/errors.