https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821

--- Comment #1 from Daniil Dudkin <dudkindaniilm2 at yandex dot ru> ---
Considering the code below the correct output would be (without the
indentation): 
  Called with constant value
  Called with non-const value
But the actual output is:
  Called with constant value
  Called with constant value

The code:
#include <cstdio>

struct WithConstant {
    static constexpr auto value = true;
};

struct WithNotConstant {
    static inline auto value = false;
};

template <auto>
concept constant_expression = true;

template <typename T>
concept with_value_constant = constant_expression<T::value>;

template <with_value_constant T>
void foo() {
    std::puts("Called with constant value");
}

template <typename T>
void foo() {
    std::puts("Called with non-const value");
}

int main() {
    foo<WithConstant>();
    foo<WithNotConstant>();
}


Compile and run logs:

$ g++-10 -v
Using built-in specs.
COLLECT_GCC=g++-10
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
10-20200411-0ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none,amdgcn-amdhsa,hsa --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.1 20200411 (experimental) [master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566] (Ubuntu
10-20200411-0ubuntu1)

$ g++-10 bug.cpp -Wall -Wextra -std=c++20
$ ./a.out
Called with constant value
Called with constant value

The godbolt link: https://godbolt.org/z/e3zvfc

The problem is reproducible with gcc 10.1, gcc 10.2 and gcc trunk also

Reply via email to