public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
@ 2023-05-07  4:16 jlame646 at gmail dot com
  2023-05-07  4:28 ` [Bug c++/109763] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: jlame646 at gmail dot com @ 2023-05-07  4:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109763
           Summary: GCC accepts invalid program involving
                    decltype(classtype::memberfunction) when used with
                    concepts
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlame646 at gmail dot com
  Target Milestone: ---

The following invalid program is accepted by gcc trunk.
https://godbolt.org/z/Ma67TTs5e

```
#include <iostream>
#include <type_traits> 
#include <concepts>
template < typename T >
concept test = std::same_as <decltype(T::func), int(int) >;
struct D
{
    int func(int);
};
int main()
{ 
    std::cout << test<D>;      
}
```
Note `decltype` on a non-static member function is not allowed and so it should
be ill-formed.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
@ 2023-05-07  4:28 ` pinskia at gcc dot gnu.org
  2023-05-07  4:29 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-07  4:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Concepts are not supposed to error out if there was an error but rather turn
into false. clang does not error out either.

GCC correctly rejects if test is defined as:
template < typename T >
constexpr bool test = std::same_as <decltype(T::func), int(int) >;

If you do:
static_assert(test<D>);

GCC will tell you know test<D> is false even:
<source>:10:15: error: static assertion failed
   10 | static_assert(test<D>);
      |               ^~~~~~~
<source>:10:15: note: constraints not satisfied
/opt/compiler-explorer/gcc-trunk-20230506/include/c++/14.0.0/concepts:57:15:  
required for the satisfaction of '__same_as<_Tp, _Up>' [with _Tp =
decltype(T::func); _Up = int(int)]
/opt/compiler-explorer/gcc-trunk-20230506/include/c++/14.0.0/concepts:62:13:  
required for the satisfaction of 'same_as<decltype (T::func), int(int)>' [with
T = D]
<source>:5:39: error: invalid use of non-static member function 'int
D::func(int)'
    5 | concept test = std::same_as <decltype(T::func), int(int) >;
      |                                       ^

concepts are supposed to be Subsitutation is not a failure proof for the reason
they are replacements for that for improved testing.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
  2023-05-07  4:28 ` [Bug c++/109763] " pinskia at gcc dot gnu.org
@ 2023-05-07  4:29 ` pinskia at gcc dot gnu.org
  2023-05-07  4:31 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-07  4:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I meant to write:
Concepts are not supposed to error out if there was an error in substitution.
So this is all by design of the language.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
  2023-05-07  4:28 ` [Bug c++/109763] " pinskia at gcc dot gnu.org
  2023-05-07  4:29 ` pinskia at gcc dot gnu.org
@ 2023-05-07  4:31 ` pinskia at gcc dot gnu.org
  2023-05-07  5:43 ` jlame646 at gmail dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-07  4:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>clang does not error out either.

Nor does MSVC :).

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-05-07  4:31 ` pinskia at gcc dot gnu.org
@ 2023-05-07  5:43 ` jlame646 at gmail dot com
  2023-05-07  5:45 ` jlame646 at gmail dot com
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jlame646 at gmail dot com @ 2023-05-07  5:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jason Liam <jlame646 at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> I meant to write:
> Concepts are not supposed to error out if there was an error in substitution.
> So this is all by design of the language.

(In reply to Andrew Pinski from comment #2)
> I meant to write:
> Concepts are not supposed to error out if there was an error in substitution.
> So this is all by design of the language.

Then why gcc rejects the following program: https://godbolt.org/z/W6d5EnvWf

```
#include <iostream>
#include <type_traits> 
#include <concepts>
struct A{
    static constexpr int value = 0;
};
template < typename T >
concept test = std::same_as <T::value, int(int) >;  
struct D
{
    int func(int);
};
int main()
{ 
    std::cout << test<D>;   //gcc rejects this but msvc accepts this
}  
```
I mean according to your given description(that concepts are not supposed to
error out...), this should also be false, right? But gcc rejects this.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-05-07  5:43 ` jlame646 at gmail dot com
@ 2023-05-07  5:45 ` jlame646 at gmail dot com
  2023-05-07  9:19 ` jlame646 at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jlame646 at gmail dot com @ 2023-05-07  5:45 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Liam <jlame646 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |---

--- Comment #5 from Jason Liam <jlame646 at gmail dot com> ---
I don't think this issue is revoved(considering that gcc
[rejects](https://godbolt.org/z/W6d5EnvWf) this.). I may be wrong though.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-05-07  5:45 ` jlame646 at gmail dot com
@ 2023-05-07  9:19 ` jlame646 at gmail dot com
  2023-05-07 10:43 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: jlame646 at gmail dot com @ 2023-05-07  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jason Liam <jlame646 at gmail dot com> ---
Looks like ill-formed no diagnostic required as per [temp.constr.normal#1.4].

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-05-07  9:19 ` jlame646 at gmail dot com
@ 2023-05-07 10:43 ` pinskia at gcc dot gnu.org
  2023-05-07 10:45 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-07 10:43 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jason Liam from comment #4)

> template < typename T >
> concept test = std::same_as <T::value, int(int) >;  

That is because the code is invalid and you need typename in front of T::value
if you want to refer to T::value as a type rather than a value here like so:
concept test = std::same_as <typename T::value, int(int) >;

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (6 preceding siblings ...)
  2023-05-07 10:43 ` pinskia at gcc dot gnu.org
@ 2023-05-07 10:45 ` pinskia at gcc dot gnu.org
  2023-05-07 11:08 ` jlame646 at gmail dot com
  2023-05-08  4:02 ` jlame646 at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-07 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Gcc correctly accepts this:
template <int t> constexpr bool d = true;
template < typename T >
concept test = d<T::value>;

Without a typename as T::value here refers to a value for the non-type template
argument.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-05-07 10:45 ` pinskia at gcc dot gnu.org
@ 2023-05-07 11:08 ` jlame646 at gmail dot com
  2023-05-08  4:02 ` jlame646 at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: jlame646 at gmail dot com @ 2023-05-07 11:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jason Liam <jlame646 at gmail dot com> ---
(In reply to Andrew Pinski from comment #8)
> Gcc correctly accepts this:
> template <int t> constexpr bool d = true;
> template < typename T >
> concept test = d<T::value>;
> 
> Without a typename as T::value here refers to a value for the non-type
> template argument.

I see. 

-------------------------------

Anyways, for my original example, [temp.constr.normal]:

> The normal form of a concept-id C<A1, A2, ..., An> is the normal form of the constraint-expression
of C, after substituting A1, A2, ..., An for C’s respective template parameters
in the parameter
mappings in each atomic constraint. If any such substitution results in an
invalid type or expression,
the program is ill-formed; no diagnostic is required.

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

* [Bug c++/109763] GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts
  2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-05-07 11:08 ` jlame646 at gmail dot com
@ 2023-05-08  4:02 ` jlame646 at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: jlame646 at gmail dot com @ 2023-05-08  4:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jason Liam <jlame646 at gmail dot com> ---
Upon reading more on this, seems this is well-formed. Note
[temp.constr.normal#1.4] is about parameter mapping(which is valid in this
case) so the last sentence in my previous quoted reference does not apply.
Instead [temp.constr.atomic#3] will apply so that the constraint is not
satisfied and hence result should be 0(which is what all compilers generate).

Thus all compilers are correct in accepting the code.

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

end of thread, other threads:[~2023-05-08  4:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-07  4:16 [Bug c++/109763] New: GCC accepts invalid program involving decltype(classtype::memberfunction) when used with concepts jlame646 at gmail dot com
2023-05-07  4:28 ` [Bug c++/109763] " pinskia at gcc dot gnu.org
2023-05-07  4:29 ` pinskia at gcc dot gnu.org
2023-05-07  4:31 ` pinskia at gcc dot gnu.org
2023-05-07  5:43 ` jlame646 at gmail dot com
2023-05-07  5:45 ` jlame646 at gmail dot com
2023-05-07  9:19 ` jlame646 at gmail dot com
2023-05-07 10:43 ` pinskia at gcc dot gnu.org
2023-05-07 10:45 ` pinskia at gcc dot gnu.org
2023-05-07 11:08 ` jlame646 at gmail dot com
2023-05-08  4:02 ` jlame646 at gmail dot com

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