public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "coyorkdow at outlook dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/108550] New: the type 'const auto' of 'constexpr' variable is not literal
Date: Thu, 26 Jan 2023 06:25:18 +0000	[thread overview]
Message-ID: <bug-108550-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108550
           Summary: the type 'const auto' of 'constexpr' variable is not
                    literal
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: coyorkdow at outlook dot com
  Target Milestone: ---

Created attachment 54344
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54344&action=edit
generated by `-save-temps`

This bug can be triggered in gcc-11 and gcc-12. (I don't have gcc-13 so I
didn't try.)

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. Other parameter like `class =
std::enable_if_t<!std::is_pointer<Tp>::value>` can also trigger.

The error also happens in gcc-12.

There is another similar but unrelated bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87512

             reply	other threads:[~2023-01-26  6:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26  6:25 coyorkdow at outlook dot com [this message]
2023-01-27  0:07 ` [Bug c++/108550] " pinskia at gcc dot gnu.org
2023-01-27  0:21 ` pinskia at gcc dot gnu.org
2023-01-27  0:24 ` [Bug c++/108550] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2023-02-20 18:19 ` mpolacek at gcc dot gnu.org
2023-02-20 18:25 ` pinskia at gcc dot gnu.org
2023-02-20 18:31 ` mpolacek at gcc dot gnu.org
2023-02-20 21:17 ` mpolacek at gcc dot gnu.org
2023-02-21 12:52 ` rguenth at gcc dot gnu.org
2023-02-21 16:28 ` mpolacek at gcc dot gnu.org
2023-02-28 15:16 ` cvs-commit at gcc dot gnu.org
2023-02-28 15:16 ` [Bug c++/108550] [10/11/12 " mpolacek at gcc dot gnu.org
2023-03-04 18:14 ` cvs-commit at gcc dot gnu.org
2023-03-04 18:18 ` mpolacek at gcc dot gnu.org
2023-03-04 18:25 ` mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108550-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).