public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111419] New: Eager instantiation of function return type in concept causes compilation error
@ 2023-09-14 17:17 ldionne.2 at gmail dot com
  2023-09-14 20:13 ` [Bug c++/111419] " ppalka at gcc dot gnu.org
  2023-09-19 12:30 ` cvs-commit at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: ldionne.2 at gmail dot com @ 2023-09-14 17:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111419
           Summary: Eager instantiation of function return type in concept
                    causes compilation error
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ldionne.2 at gmail dot com
  Target Milestone: ---

The following code fails to compile on GCC:

------------------------------------------------------------
  template <class F>
  auto invoke(F f) -> decltype(f());

  template <class F>
  concept invocable = requires(F&& f) {
    ::invoke(f);
  };

  struct Incomplete;
  template<class T> struct Holder { T t; };

  static_assert(invocable<Holder<Incomplete>& ()>);
------------------------------------------------------------

It produces the following error on GCC:

  <source>: In instantiation of 'struct Holder<Incomplete>':
  <source>:6:11:   required from here
  <source>:10:37: error: 'Holder<T>::t' has incomplete type
    10 | template<class T> struct Holder { T t; };
        |                                     ^
  <source>:9:8: note: forward declaration of 'struct Incomplete'
      9 | struct Incomplete;
        |        ^~~~~~~~~~
  Compiler returned: 1

My understanding is that this should be valid, because nothing actually
requires instantiating the return type of `f()` here, but I'm not sufficiently
well-versed in the details of concepts to know for sure.

Clang and MSVC accept the code.
Godbolt: https://godbolt.org/z/9G5zj47an

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

* [Bug c++/111419] Eager instantiation of function return type in concept causes compilation error
  2023-09-14 17:17 [Bug c++/111419] New: Eager instantiation of function return type in concept causes compilation error ldionne.2 at gmail dot com
@ 2023-09-14 20:13 ` ppalka at gcc dot gnu.org
  2023-09-19 12:30 ` cvs-commit at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-09-14 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-09-14
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org
           Keywords|                            |rejects-valid
     Ever confirmed|0                           |1

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, not a regression.  Related C++98 testcase:

template<class T>
struct A { T t; };

void f(A<void>& a) {
  a;
}

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

* [Bug c++/111419] Eager instantiation of function return type in concept causes compilation error
  2023-09-14 17:17 [Bug c++/111419] New: Eager instantiation of function return type in concept causes compilation error ldionne.2 at gmail dot com
  2023-09-14 20:13 ` [Bug c++/111419] " ppalka at gcc dot gnu.org
@ 2023-09-19 12:30 ` cvs-commit at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-19 12:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:b510b83aad52adf94d52a6ae3a3b332946e947a1

commit r14-4138-gb510b83aad52adf94d52a6ae3a3b332946e947a1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Sep 19 08:29:39 2023 -0400

    c++: overeager type completion in convert_to_void [PR111419]

    Here convert_to_void always completes the type of an indirection or
    id-expression, but according to [expr.context] an lvalue-to-rvalue
    conversion is applied to a discarded-value expression only if "the
    expression is a glvalue of volatile-qualified type".  This patch
    restricts convert_to_void's type completion to match.

            PR c++/111419

    gcc/cp/ChangeLog:

            * cvt.cc (convert_to_void) <case INDIRECT_REF>: Only call
            complete_type if the type is volatile.
            <case VAR_DECL>: Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/concepts-requires36.C: New test.
            * g++.dg/expr/discarded1.C: New test.
            * g++.dg/expr/discarded1a.C: New test.

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

end of thread, other threads:[~2023-09-19 12:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 17:17 [Bug c++/111419] New: Eager instantiation of function return type in concept causes compilation error ldionne.2 at gmail dot com
2023-09-14 20:13 ` [Bug c++/111419] " ppalka at gcc dot gnu.org
2023-09-19 12:30 ` cvs-commit 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).