public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113242] New: g++ rejects-valid template argument of class type containing an lvalue reference
@ 2024-01-05 12:34 janschultke at googlemail dot com
  2024-01-05 16:54 ` [Bug c++/113242] " ppalka at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: janschultke at googlemail dot com @ 2024-01-05 12:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113242
           Summary: g++ rejects-valid template argument of class type
                    containing an lvalue reference
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janschultke at googlemail dot com
  Target Milestone: ---

## Code to Reproduce

struct wrapper {
    int& ref;
    constexpr wrapper(int& ref) : ref(ref) {}
};

template <const wrapper& X>
void fun1() {}

template <wrapper X>
void fun2() {
    fun1<X>();
}

int main() {
    static int val = 22;
    fun2<val>();
}


## Incorrect Output (GCC 14, -std=c++20) (https://godbolt.org/z/1jzqza73z)

<source>: In instantiation of 'void fun2() [with wrapper X = wrapper{val}]':
<source>:16:14:   required from here
   16 |     fun2<val>();
      |     ~~~~~~~~~^~
<source>:11:12: error: no matching function for call to 'fun1<wrapper{val}>()'
   11 |     fun1<X>();
      |     ~~~~~~~^~
<source>:7:6: note: candidate: 'template<const wrapper& X> void fun1()'
    7 | void fun1() {}
      |      ^~~~
<source>:7:6: note:   template argument deduction/substitution failed:
<source>:11:12: error: the address of 'wrapper{val}' is not a valid template
argument
   11 |     fun1<X>();
      |     ~~~~~~~^~

## Explanation

None. Clang compiles this, but GCC doesn't. The reference contained within
wrapper is a valid template argument (see
https://eel.is/c++draft/temp.arg.nontype#6), but falsely disqualifies X in fun1
from binding to X in fun2.

See https://stackoverflow.com/a/77764351/5740428 for a more detailed
explanation for the relevant standardese.

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

* [Bug c++/113242] g++ rejects-valid template argument of class type containing an lvalue reference
  2024-01-05 12:34 [Bug c++/113242] New: g++ rejects-valid template argument of class type containing an lvalue reference janschultke at googlemail dot com
@ 2024-01-05 16:54 ` ppalka at gcc dot gnu.org
  2024-01-17 18:02 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-05 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-01-05
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed, this never worked.

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

* [Bug c++/113242] g++ rejects-valid template argument of class type containing an lvalue reference
  2024-01-05 12:34 [Bug c++/113242] New: g++ rejects-valid template argument of class type containing an lvalue reference janschultke at googlemail dot com
  2024-01-05 16:54 ` [Bug c++/113242] " ppalka at gcc dot gnu.org
@ 2024-01-17 18:02 ` cvs-commit at gcc dot gnu.org
  2024-01-18 15:53 ` cvs-commit at gcc dot gnu.org
  2024-01-18 15:54 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-17 18:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from GCC 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:68cea2d32a9fd525154b6a48042e5835d4c5e371

commit r14-8189-g68cea2d32a9fd525154b6a48042e5835d4c5e371
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jan 17 13:01:01 2024 -0500

    c++: address of class NTTP object as targ [PR113242]

    invalid_tparm_referent_p was rejecting using the address of a class NTTP
    object as a template argument, but this should be fine.

            PR c++/113242
            PR c++/99493

    gcc/cp/ChangeLog:

            * pt.cc (invalid_tparm_referent_p) <case ADDR_EXPR>: Suppress
            DECL_ARTIFICIAL rejection test for class NTTP objects.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/nontype-class61.C: New test.
            * g++.dg/cpp2a/nontype-class62.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>

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

* [Bug c++/113242] g++ rejects-valid template argument of class type containing an lvalue reference
  2024-01-05 12:34 [Bug c++/113242] New: g++ rejects-valid template argument of class type containing an lvalue reference janschultke at googlemail dot com
  2024-01-05 16:54 ` [Bug c++/113242] " ppalka at gcc dot gnu.org
  2024-01-17 18:02 ` cvs-commit at gcc dot gnu.org
@ 2024-01-18 15:53 ` cvs-commit at gcc dot gnu.org
  2024-01-18 15:54 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-18 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:4ffb23975b32bfd285915c3d6659b837868b5aa9

commit r13-8235-g4ffb23975b32bfd285915c3d6659b837868b5aa9
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Jan 17 13:01:01 2024 -0500

    c++: address of class NTTP object as targ [PR113242]

    invalid_tparm_referent_p was rejecting using the address of a class NTTP
    object as a template argument, but this should be fine.

            PR c++/113242
            PR c++/99493

    gcc/cp/ChangeLog:

            * pt.cc (invalid_tparm_referent_p) <case ADDR_EXPR>: Suppress
            DECL_ARTIFICIAL rejection test for class NTTP objects.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/nontype-class61.C: New test.
            * g++.dg/cpp2a/nontype-class62.C: New test.

    Reviewed-by: Jason Merrill <jason@redhat.com>
    (cherry picked from commit 68cea2d32a9fd525154b6a48042e5835d4c5e371)

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

* [Bug c++/113242] g++ rejects-valid template argument of class type containing an lvalue reference
  2024-01-05 12:34 [Bug c++/113242] New: g++ rejects-valid template argument of class type containing an lvalue reference janschultke at googlemail dot com
                   ` (2 preceding siblings ...)
  2024-01-18 15:53 ` cvs-commit at gcc dot gnu.org
@ 2024-01-18 15:54 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2024-01-18 15:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |13.3

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13.3 / 14.

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

end of thread, other threads:[~2024-01-18 15:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-05 12:34 [Bug c++/113242] New: g++ rejects-valid template argument of class type containing an lvalue reference janschultke at googlemail dot com
2024-01-05 16:54 ` [Bug c++/113242] " ppalka at gcc dot gnu.org
2024-01-17 18:02 ` cvs-commit at gcc dot gnu.org
2024-01-18 15:53 ` cvs-commit at gcc dot gnu.org
2024-01-18 15:54 ` 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).