public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95132] New: Concept checked after auto return type deduction
@ 2020-05-14 13:50 bluescarni at gmail dot com
  2020-05-14 15:26 ` [Bug c++/95132] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: bluescarni at gmail dot com @ 2020-05-14 13:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95132
           Summary: Concept checked after auto return type deduction
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bluescarni at gmail dot com
  Target Milestone: ---

It seems like in GCC's implementation of C++20 concepts, concept checking is
done after the instantiation of the body of a function with auto return type
deduction.

See the godbolt link, where the same snippet of code is being compiled with
GCC, clang and MSVC:

https://godbolt.org/z/CMzZyV

As you see, the first GCC error comes from the failure in the instantiation of
the body of function bar(), and only later GCC complains about the concept
check failure. The other two compilers don't produce any error from the
instantiation of bar().

This is problematic because it means that another concept that would check
whether or not bar() can be called with a specific argument type would fail
with a hard compile time error, instead of marking the concept as not
satisfied.

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

* [Bug c++/95132] Concept checked after auto return type deduction
  2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
@ 2020-05-14 15:26 ` redi at gcc dot gnu.org
  2020-05-15 13:57 ` ppalka at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2020-05-14 15:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-05-14
             Status|UNCONFIRMED                 |WAITING

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Please read https://gcc.gnu.org/bugs (as requested when creating a bug) and
provide the missing information.

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

* [Bug c++/95132] Concept checked after auto return type deduction
  2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
  2020-05-14 15:26 ` [Bug c++/95132] " redi at gcc dot gnu.org
@ 2020-05-15 13:57 ` ppalka at gcc dot gnu.org
  2020-10-25 19:27 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-05-15 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Francesco Biscani from comment #0)
> This is problematic because it means that another concept that would check
> whether or not bar() can be called with a specific argument type would fail
> with a hard compile time error, instead of marking the concept as not
> satisfied.

Would you have a concrete testcase for this behavior?

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

* [Bug c++/95132] Concept checked after auto return type deduction
  2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
  2020-05-14 15:26 ` [Bug c++/95132] " redi at gcc dot gnu.org
  2020-05-15 13:57 ` ppalka at gcc dot gnu.org
@ 2020-10-25 19:27 ` ppalka at gcc dot gnu.org
  2020-10-28 15:47 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-10-25 19:27 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
   Target Milestone|---                         |10.3

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #2)
> (In reply to Francesco Biscani from comment #0)
> > This is problematic because it means that another concept that would check
> > whether or not bar() can be called with a specific argument type would fail
> > with a hard compile time error, instead of marking the concept as not
> > satisfied.
> 
> Would you have a concrete testcase for this behavior?

Ah, here's one:

$ cat testcase.C
template<typename T> struct A {
  static auto f() requires false { return T::fail; }
};

template<typename T>
constexpr int v = requires { A<T>::f(); };

static_assert(!v<int>);

$ g++ -std=c++20 testcase.C
testcase.C: In instantiation of ‘static auto A<T>::f() requires  false [with T
= int]’:
testcase.C:   required from ‘constexpr const int v<int>’
testcase.C:   required from here
testcase.C: error: ‘fail’ is not a member of ‘int’
    2 |   static auto f() requires false { return T::fail; }
      |                                              ^~~~


We wrongly issue a hard error for the reason you pointed out.

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

* [Bug c++/95132] Concept checked after auto return type deduction
  2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
                   ` (2 preceding siblings ...)
  2020-10-25 19:27 ` ppalka at gcc dot gnu.org
@ 2020-10-28 15:47 ` cvs-commit at gcc dot gnu.org
  2020-10-28 21:25 ` cvs-commit at gcc dot gnu.org
  2020-10-28 21:34 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-28 15:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:9ccc3495766116ea4ae8e4cd8129beca60e30445

commit r11-4488-g9ccc3495766116ea4ae8e4cd8129beca60e30445
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Oct 28 11:47:26 2020 -0400

    c++: Check constraints before instantiation from mark_used [PR95132]

    This makes mark_used check constraints of a function _before_ calling
    maybe_instantiate_decl, so that we don't try instantiating a function
    (as part of return type deduction) with unsatisfied constraints.

    gcc/cp/ChangeLog:

            PR c++/95132
            * decl2.c (mark_used): Move up the constraints_satisfied_p check
            so that we check constraints before calling maybe_instantiate_decl.

    gcc/testsuite/ChangeLog:

            PR c++/95132
            * g++.dg/cpp2a/concepts-fn7.C: New test.

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

* [Bug c++/95132] Concept checked after auto return type deduction
  2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
                   ` (3 preceding siblings ...)
  2020-10-28 15:47 ` cvs-commit at gcc dot gnu.org
@ 2020-10-28 21:25 ` cvs-commit at gcc dot gnu.org
  2020-10-28 21:34 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-28 21:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:833b180f097e8bae44634e6a31e9c92d661af301

commit r10-8951-g833b180f097e8bae44634e6a31e9c92d661af301
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Oct 28 11:47:26 2020 -0400

    c++: Check constraints before instantiation from mark_used [PR95132]

    This makes mark_used check constraints of a function _before_ calling
    maybe_instantiate_decl, so that we don't try instantiating a function
    (as part of return type deduction) with unsatisfied constraints.

    gcc/cp/ChangeLog:

            PR c++/95132
            * decl2.c (mark_used): Move up the constraints_satisfied_p check
            so that we check constraints before calling maybe_instantiate_decl.

    gcc/testsuite/ChangeLog:

            PR c++/95132
            * g++.dg/cpp2a/concepts-fn7.C: New test.

    (cherry picked from commit 9ccc3495766116ea4ae8e4cd8129beca60e30445)

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

* [Bug c++/95132] Concept checked after auto return type deduction
  2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
                   ` (4 preceding siblings ...)
  2020-10-28 21:25 ` cvs-commit at gcc dot gnu.org
@ 2020-10-28 21:34 ` ppalka at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-10-28 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 10.3+, thanks for the bug report.

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

end of thread, other threads:[~2020-10-28 21:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-14 13:50 [Bug c++/95132] New: Concept checked after auto return type deduction bluescarni at gmail dot com
2020-05-14 15:26 ` [Bug c++/95132] " redi at gcc dot gnu.org
2020-05-15 13:57 ` ppalka at gcc dot gnu.org
2020-10-25 19:27 ` ppalka at gcc dot gnu.org
2020-10-28 15:47 ` cvs-commit at gcc dot gnu.org
2020-10-28 21:25 ` cvs-commit at gcc dot gnu.org
2020-10-28 21:34 ` 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).