public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102884] New: Incorrect compile error with id-expression in requires clause before member initializer
@ 2021-10-21 16:14 galston at stellarscience dot com
  2021-10-21 16:24 ` [Bug c++/102884] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: galston at stellarscience dot com @ 2021-10-21 16:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102884
           Summary: Incorrect compile error with id-expression in requires
                    clause before member initializer
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: galston at stellarscience dot com
  Target Milestone: ---

Created attachment 51645
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51645&action=edit
.ii file produced by g++ command

This compiles in MSVC and clang, but gives a compile error in gcc:

constexpr bool kExpression{ true };

struct Foo {

  template< typename T >
  Foo(T ) requires kExpression : x{0} {}

  int x;
};

int main() {
  [[maybe_unused]] Foo foo{1};
}

It will compile if parentheses are put around kExpression. Since kExpression is
an id-expression, and an id-expression is a primary expression, I think this
should be allowed as is in a requires clause (see Requires clause section here
https://en.cppreference.com/w/cpp/language/constraints). It appears to be the
member initializer that it is choking on; it will compile if the ": x{0}" part
is removed.

Thank you!

Output from gcc:

> g++ -v -save-temps -Wall -Werror -std=c++20 -c requires-clause-bug.cpp
Using built-in specs.
COLLECT_GCC=g++
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-11.2.1-20210728/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Werror' '-std=c++20' '-c'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/11/cc1plus -E -quiet -v -D_GNU_SOURCE
requires-clause-bug.cpp -mtune=generic -march=x86-64 -std=c++20 -Wall -Werror
-fpch-preprocess -o requires-clause-bug.ii
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/11/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/11/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11

/usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/x86_64-redhat-linux
 /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/backward
 /usr/lib/gcc/x86_64-redhat-linux/11/include
 /usr/local/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Werror' '-std=c++20' '-c'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/libexec/gcc/x86_64-redhat-linux/11/cc1plus -fpreprocessed
requires-clause-bug.ii -quiet -dumpbase requires-clause-bug.cpp -dumpbase-ext
.cpp -mtune=generic -march=x86-64 -Wall -Werror -std=c++20 -version -o
requires-clause-bug.s
GNU C++20 (GCC) version 11.2.1 20210728 (Red Hat 11.2.1-1)
(x86_64-redhat-linux)
        compiled by GNU C version 11.2.1 20210728 (Red Hat 11.2.1-1), GMP
version 6.2.0, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version
isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++20 (GCC) version 11.2.1 20210728 (Red Hat 11.2.1-1)
(x86_64-redhat-linux)
        compiled by GNU C version 11.2.1 20210728 (Red Hat 11.2.1-1), GMP
version 6.2.0, MPFR version 4.1.0-p13, MPC version 1.2.1, isl version
isl-0.18-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ee1a2f208dd48c6a5d24bdcd31126e66
requires-clause-bug.cpp:7:32: error: found ‘:’ in nested-name-specifier,
expected ‘::’
    7 |   Foo(T ) requires kExpression : x{0} {}
      |                                ^
      |                                ::
requires-clause-bug.cpp:7:20: error: ‘kExpression’ is not a class, namespace,
or enumeration
    7 |   Foo(T ) requires kExpression : x{0} {}
      |                    ^~~~~~~~~~~
requires-clause-bug.cpp:7:39: error: expected unqualified-id before ‘{’ token
    7 |   Foo(T ) requires kExpression : x{0} {}
      |                                       ^
requires-clause-bug.cpp: In constructor ‘Foo::Foo(T) requires 
<erroneous-expression>’:
requires-clause-bug.cpp:7:37: error: expected ‘;’ before ‘}’ token
    7 |   Foo(T ) requires kExpression : x{0} {}
      |                                     ^
requires-clause-bug.cpp: In function ‘int main()’:
requires-clause-bug.cpp:13:29: error: no matching function for call to
‘Foo::Foo(<brace-enclosed initializer list>)’
   13 |   [[maybe_unused]] Foo foo{1};
      |                             ^
requires-clause-bug.cpp:7:3: note: candidate: ‘template<class T> Foo::Foo(T)
requires  <erroneous-expression>’
    7 |   Foo(T ) requires kExpression : x{0} {}
      |   ^~~
requires-clause-bug.cpp:7:3: note:   template argument deduction/substitution
failed:
requires-clause-bug.cpp:7:3: note: constraints not satisfied
requires-clause-bug.cpp:3:8: note: candidate: ‘constexpr Foo::Foo(const Foo&)’
    3 | struct Foo {
      |        ^~~
requires-clause-bug.cpp:3:8: note:   no known conversion for argument 1 from
‘int’ to ‘const Foo&’
requires-clause-bug.cpp:3:8: note: candidate: ‘constexpr Foo::Foo(Foo&&)’
requires-clause-bug.cpp:3:8: note:   no known conversion for argument 1 from
‘int’ to ‘Foo&&’

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/102884] Incorrect compile error with id-expression in requires clause before member initializer
  2021-10-21 16:14 [Bug c++/102884] New: Incorrect compile error with id-expression in requires clause before member initializer galston at stellarscience dot com
@ 2021-10-21 16:24 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-21 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |rejects-valid
   Last reconfirmed|                            |2021-10-21

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-21 16:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 16:14 [Bug c++/102884] New: Incorrect compile error with id-expression in requires clause before member initializer galston at stellarscience dot com
2021-10-21 16:24 ` [Bug c++/102884] " redi at gcc dot gnu.org

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).