public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression
@ 2020-08-27 17:26 dudkindaniilm2 at yandex dot ru
2020-08-27 17:27 ` [Bug c++/96821] " dudkindaniilm2 at yandex dot ru
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: dudkindaniilm2 at yandex dot ru @ 2020-08-27 17:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
Bug ID: 96821
Summary: [concepts] Incorrect evaluation of concept with
ill-formed expression
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dudkindaniilm2 at yandex dot ru
Target Milestone: ---
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
@ 2020-08-27 17:27 ` dudkindaniilm2 at yandex dot ru
2020-08-28 22:02 ` dudkindaniilm2 at yandex dot ru
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dudkindaniilm2 at yandex dot ru @ 2020-08-27 17:27 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
2020-08-27 17:27 ` [Bug c++/96821] " dudkindaniilm2 at yandex dot ru
@ 2020-08-28 22:02 ` dudkindaniilm2 at yandex dot ru
2020-09-21 16:00 ` ppalka at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: dudkindaniilm2 at yandex dot ru @ 2020-08-28 22:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
--- Comment #2 from Daniil Dudkin <dudkindaniilm2 at yandex dot ru> ---
Basically it described in 4th paragraph in [temp.constr.decl] of the latest C++
standard draft:
http://eel.is/c++draft/temp.constr.decl#4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
2020-08-27 17:27 ` [Bug c++/96821] " dudkindaniilm2 at yandex dot ru
2020-08-28 22:02 ` dudkindaniilm2 at yandex dot ru
@ 2020-09-21 16:00 ` ppalka at gcc dot gnu.org
2021-01-18 16:36 ` ppalka at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-09-21 16:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
Known to fail| |10.2.0, 11.0, 9.3.0
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2020-09-21
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed. One workaround is to define with_value_constant as
template <typename T>
concept with_value_constant
= requires { constant_expression<T::value>; };
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
` (2 preceding siblings ...)
2020-09-21 16:00 ` ppalka at gcc dot gnu.org
@ 2021-01-18 16:36 ` ppalka at gcc dot gnu.org
2021-02-03 19:28 ` dudkindaniilm2 at yandex dot ru
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-01-18 16:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
GCC's behaviour is correct, I think. Since the concept constant_expression
doesn't use its template parameter, the normal form of foo's associated
constraint is just 'true (with an empty parameter mapping)', so the
satisfaction value of with_value_constant<T> for any T is trivially true and
independent of T.
Another workaround to have the with_value_constant concept work as you expect
is to make the constant_expression concept depend on its template parameter in
a trivial way, e.g. define it as:
template <auto V>
concept constant_expression = requires { V; };
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
` (3 preceding siblings ...)
2021-01-18 16:36 ` ppalka at gcc dot gnu.org
@ 2021-02-03 19:28 ` dudkindaniilm2 at yandex dot ru
2021-05-09 21:31 ` zamazan4ik at tut dot by
2021-05-10 3:08 ` ppalka at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: dudkindaniilm2 at yandex dot ru @ 2021-02-03 19:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
Daniil Dudkin <dudkindaniilm2 at yandex dot ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |---
Status|RESOLVED |REOPENED
--- Comment #5 from Daniil Dudkin <dudkindaniilm2 at yandex dot ru> ---
(In reply to Patrick Palka from comment #4)
> GCC's behaviour is correct, I think. Since the concept constant_expression
> doesn't use its template parameter, the normal form of foo's associated
> constraint is just 'true (with an empty parameter mapping)', so the
> satisfaction value of with_value_constant<T> for any T is trivially true and
> independent of T.
No, I don't think that GCC behaviour is correct.
http://eel.is/c++draft/temp.constr#atomic-3
> If substitution results in an invalid type or expression, the constraint is not satisfied.
The substitution with_value_constant<WithNotConstant::value> results in an
invalid expression because WithNotConstant::value is not a constant expression,
so it cannot be used as a non-type template argument. That means
with_value_constant<WithNotConstant::value> should be false regardless how
with_value_constant is defined.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
` (4 preceding siblings ...)
2021-02-03 19:28 ` dudkindaniilm2 at yandex dot ru
@ 2021-05-09 21:31 ` zamazan4ik at tut dot by
2021-05-10 3:08 ` ppalka at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: zamazan4ik at tut dot by @ 2021-05-09 21:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
Alexander Zaitsev <zamazan4ik at tut dot by> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |zamazan4ik at tut dot by
--- Comment #6 from Alexander Zaitsev <zamazan4ik at tut dot by> ---
Any updates on the issue? Such behaviour is strange too since Clang and MSVC
have a different opinion from GCC for the code.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/96821] [concepts] Incorrect evaluation of concept with ill-formed expression
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
` (5 preceding siblings ...)
2021-05-09 21:31 ` zamazan4ik at tut dot by
@ 2021-05-10 3:08 ` ppalka at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-05-10 3:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96821
--- Comment #7 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Daniil Dudkin from comment #5)
> (In reply to Patrick Palka from comment #4)
> > GCC's behaviour is correct, I think. Since the concept constant_expression
> > doesn't use its template parameter, the normal form of foo's associated
> > constraint is just 'true (with an empty parameter mapping)', so the
> > satisfaction value of with_value_constant<T> for any T is trivially true and
> > independent of T.
>
>
> No, I don't think that GCC behaviour is correct.
>
> http://eel.is/c++draft/temp.constr#atomic-3
>
> > If substitution results in an invalid type or expression, the constraint is not satisfied.
'Substitution' here refers to substitution into the atomic constraints of a
constraint-expression, not into the constraint-expression directly. Atomic
constraints are formed via constraint normalization. In the case of
with_value_constant<T>, normalization of this constraint-expression yields the
single atomic constraint 'true (with an empty parameter mapping)' as per
[temp.constr.atomic]/1 and [temp.constr.normal]. The substitution
'T=WithNonConstant' into this atomic constraint will never fail, because the
atomic constraint doesn't depend on any template parameters.
>
> The substitution with_value_constant<WithNotConstant::value> results in an
> invalid expression because WithNotConstant::value is not a constant
> expression, so it cannot be used as a non-type template argument. That means
> with_value_constant<WithNotConstant::value> should be false regardless how
> with_value_constant is defined.
As mentioned before, you need to make the concept constant_expression depend on
its template parameter so that normalization doesn't throw away the 'T::value'
template argument inside the definition of with_value_constant.
(In reply to Alexander Zaitsev from comment #6)
> Any updates on the issue? Such behaviour is strange too since Clang and MSVC
> have a different opinion from GCC for the code.
I think GCC is behaving correctly here.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-05-10 3:08 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 17:26 [Bug c++/96821] New: [concepts] Incorrect evaluation of concept with ill-formed expression dudkindaniilm2 at yandex dot ru
2020-08-27 17:27 ` [Bug c++/96821] " dudkindaniilm2 at yandex dot ru
2020-08-28 22:02 ` dudkindaniilm2 at yandex dot ru
2020-09-21 16:00 ` ppalka at gcc dot gnu.org
2021-01-18 16:36 ` ppalka at gcc dot gnu.org
2021-02-03 19:28 ` dudkindaniilm2 at yandex dot ru
2021-05-09 21:31 ` zamazan4ik at tut dot by
2021-05-10 3:08 ` ppalka 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).