[Bug c++/87512] Error: the type ‘const auto’ of ‘constexpr’ variable is not literal

coyorkdow at outlook dot com gcc-bugzilla@gcc.gnu.org
Wed Jan 25 09:27:37 GMT 2023


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

--- Comment #5 from Guo Youtao <coyorkdow at outlook dot com> ---
This bug can still be triggered in gcc-11 and gcc-12.

Here are the codes (the preprocessed file is attached)
```
#include <type_traits>
#include <memory>

template <class Tp>
constexpr auto is_pointer_v = std::is_pointer<Tp>::value;

template <class Tp, decltype(&Tp::operator*)* = nullptr>
auto Wrap1(int) -> std::integral_constant<bool,
is_pointer_v<decltype(std::declval<Tp>().operator->())>>;

template <class Tp>
auto Wrap1(...) -> std::is_pointer<Tp>;

int main() {
  static_assert(!is_pointer_v<std::unique_ptr<int>>); // this line can compile
  static_assert(decltype(Wrap1<std::unique_ptr<int>>(0))::value); // error
  return 0;
}
```

The err msgs
```
% g++-11 a.cc -save-temps
a.cc: In instantiation of 'constexpr const auto is_pointer_v<int*>':
a.cc:8:49:   required by substitution of 'template<class Tp, decltype (&
Tp::operator*)* <anonymous> > std::integral_constant<bool,
is_pointer_v<decltype (declval<Tp>().operator->())> > Wrap1(int) [with Tp =
std::unique_ptr<int>; decltype (& Tp::operator*)* <anonymous> = <missing>]'
a.cc:15:53:   required from here
a.cc:5:16: error: the type 'const auto' of 'constexpr' variable
'is_pointer_v<int*>' is not literal
    5 | constexpr auto is_pointer_v = std::is_pointer<Tp>::value;
      |                ^~~~~~~~~~~~
a.cc:5:16: error: 'const auto is_pointer_v<int*>' has incomplete type
a.cc: In function 'int main()':
a.cc:15:59: error: static assertion failed
   15 |   static_assert(decltype(Wrap1<std::unique_ptr<int>>(0))::value); //
this line incurs error
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
```


GCC version:
```
% gcc-11 -v
Using built-in specs.
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.3.0_2/bin/../libexec/gcc/x86_64-apple-darwin21/11/lto-wrapper
Target: x86_64-apple-darwin21
Configured with: ../configure --prefix=/usr/local/opt/gcc
--libdir=/usr/local/opt/gcc/lib/gcc/11 --disable-nls --enable-checking=release
--with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d
--program-suffix=-11 --with-gmp=/usr/local/opt/gmp
--with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc
--with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd
--with-pkgversion='Homebrew GCC 11.3.0_2'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Homebrew GCC 11.3.0_2)
```

If remove the parameter `decltype(&Tp::operator*)* = nullptr` then codes can be
compiled.

The error also happens in gcc-12.


More information about the Gcc-bugs mailing list