public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter
@ 2024-06-26  1:42 s.murthy at outlook dot com
  2024-06-26  1:48 ` [Bug c++/115656] " s.murthy at outlook dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-26  1:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115656
           Summary: Templated ctor use rejected in non-deduced context if
                    class template has template template parameter
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: s.murthy at outlook dot com
  Target Milestone: ---

Using a class constructor in a non-deduced context (when no CTAD is being
attempted, saying that in case my terminology is incorrect) causes an error if
the class template has a template template parameter (lass template A in
repro). Oddly, the error disappears if CTAD is engaged before the erring code.

This is a regression: no issue in GCC 10.5, but issue since GCC 11.1.

Aside, clang accepts this code (from 11.0 to current version)

PS: I searched the bug database and found no report matching this issue, but I
apologize if this issue is known.

Repro below (online https://sigcpp.godbolt.org/z/M1eoE485x):
------------------------------------------------------------

//stub for use in class template A
template<std::unsigned_integral U = unsigned> class dv;

//class template A with template template parameter
template<std::unsigned_integral U = unsigned,
         template <std::unsigned_integral> class V = dv
        >
struct A 
{
    U u_;

    A(U u) : u_(u) {};

    template<std::signed_integral S>
    A(S s) : u_( s < 0 ? -s : s) {}
};


//same as class A but no template template parameter
template<std::unsigned_integral U = unsigned>
struct B 
{
    U u_;

    B(U u) : u_(u) {};

    template<std::signed_integral S>
    B(S s) : u_( s < 0 ? -s : s) {}
};

int main()
{
    //A a1(45ul);
    A a2(45l); //Error CGCC 11.5+: uncomment line above, the error disappears

    B b2(45l); //OK
}

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

* [Bug c++/115656] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
@ 2024-06-26  1:48 ` s.murthy at outlook dot com
  2024-06-26  3:57 ` s.murthy at outlook dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-26  1:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Sean Murthy <s.murthy at outlook dot com> ---
Oops. I meant to say "GCC 11.1" in my bug description; not GCC 11.5. It looks
like I can't edit the description. So, please make that a mental correction. 😳

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

* [Bug c++/115656] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
  2024-06-26  1:48 ` [Bug c++/115656] " s.murthy at outlook dot com
@ 2024-06-26  3:57 ` s.murthy at outlook dot com
  2024-06-26  4:13 ` s.murthy at outlook dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-26  3:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Sean Murthy <s.murthy at outlook dot com> ---
Compiler version: GCC 11.1 through GCC 14.1

Compiler options: -std=c++20 -Wall -Wextra -pedantic -pedantic-errors
-Werror=pedantic

Compiler output:

<source>: In function 'int main()':
<source>:39:13: error: class template argument deduction failed:
   39 |     A a2(45l); //Error GCC 11.1+: uncomment line above, the error
disappears
      |             ^
<source>:39:13: error: no matching function for call to 'A(long int)'
<source>:20:5: note: candidate: 'template<class U, template<class> class
requires  unsigned_integral< <template-parameter-2-1> > V, class S>  requires 
signed_integral<S> A(S)-> A<U, V>'
   20 |     A(S s) : u_( s < 0 ? -s : s) {}
      |     ^
<source>:20:5: note:   template argument deduction/substitution failed:
<source>: In substitution of 'template<class U, template<class> class requires 
unsigned_integral< <template-parameter-2-1> > V, class S>  requires 
signed_integral<S> A(S)-> A<U, V> [with U = unsigned int; V = dv; S = long
int]':
<source>:39:13:   required from here
   39 |     A a2(45l); //Error GCC 11.1+: uncomment line above, the error
disappears
      |             ^
<source>:20:5: error: template constraint failure for 'template<class U,
template<class> class requires  unsigned_integral< <template-parameter-2-1> >
V>  requires  unsigned_integral<U> struct A'
   20 |     A(S s) : u_( s < 0 ? -s : s) {}
      |     ^
<source>:20:5: note: constraints not satisfied
<source>:17:5: note: candidate: 'template<class U, template<class> class
requires  unsigned_integral< <template-parameter-2-1> > V> A(U)-> A<U, V>'
   17 |     A(U u) : u_(u) {};
      |     ^
<source>:17:5: note:   template argument deduction/substitution failed:
<source>:13:8: note: candidate: 'template<class U, template<class> class
requires  unsigned_integral< <template-parameter-2-1> > V> A(A<U, V>)-> A<U,
V>'
   13 | struct A
      |        ^
<source>:13:8: note:   template argument deduction/substitution failed:
<source>:39:13: note:   mismatched types 'A<U, V>' and 'long int'
   39 |     A a2(45l); //Error GCC 11.1+: uncomment line above, the error
disappears
      |             ^

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

* [Bug c++/115656] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
  2024-06-26  1:48 ` [Bug c++/115656] " s.murthy at outlook dot com
  2024-06-26  3:57 ` s.murthy at outlook dot com
@ 2024-06-26  4:13 ` s.murthy at outlook dot com
  2024-06-26  4:26 ` s.murthy at outlook dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-26  4:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Sean Murthy <s.murthy at outlook dot com> ---
Created attachment 58516
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58516&action=edit
preprocessed file for the source with repro

This pre-processed was generated by running the following command:

g++ -v -save-temps -std=c++20 -Wall -Wextra -pedantic -pedantic-errors
-Werror=pedantic main.cpp

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

* [Bug c++/115656] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
                   ` (2 preceding siblings ...)
  2024-06-26  4:13 ` s.murthy at outlook dot com
@ 2024-06-26  4:26 ` s.murthy at outlook dot com
  2024-06-26  7:31 ` [Bug c++/115656] [11/12/13/14/15 Regression] " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-26  4:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Sean Murthy <s.murthy at outlook dot com> ---
Created attachment 58517
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58517&action=edit
g++ output

This file contains the compiler output using the following cmdline on the
source file containing the repro code:

g++ -v -save-temps -std=c++20 -Wall -Wextra -pedantic -pedantic-errors
-Werror=pedantic main.cpp

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

* [Bug c++/115656] [11/12/13/14/15 Regression] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
                   ` (3 preceding siblings ...)
  2024-06-26  4:26 ` s.murthy at outlook dot com
@ 2024-06-26  7:31 ` rguenth at gcc dot gnu.org
  2024-06-26 14:00 ` mpolacek at gcc dot gnu.org
  2024-06-26 19:24 ` s.murthy at outlook dot com
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-26  7:31 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.5
            Summary|Templated ctor use rejected |[11/12/13/14/15 Regression]
                   |in non-deduced context if   |Templated ctor use rejected
                   |class template has template |in non-deduced context if
                   |template parameter          |class template has template
                   |                            |template parameter
      Known to work|                            |10.5.0
           Keywords|                            |needs-bisection,
                   |                            |rejects-valid

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

* [Bug c++/115656] [11/12/13/14/15 Regression] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
                   ` (4 preceding siblings ...)
  2024-06-26  7:31 ` [Bug c++/115656] [11/12/13/14/15 Regression] " rguenth at gcc dot gnu.org
@ 2024-06-26 14:00 ` mpolacek at gcc dot gnu.org
  2024-06-26 19:24 ` s.murthy at outlook dot com
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-06-26 14:00 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
                 CC|                            |mpolacek at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
   Last reconfirmed|                            |2024-06-26
     Ever confirmed|0                           |1
           Keywords|needs-bisection             |
           Priority|P3                          |P2

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r11-4859:

commit d3fd75d869480044213553000d2c9dc236a4f7af
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Nov 9 18:16:48 2020 -0500

    c++: Consider only relevant template arguments in sat_hasher

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

* [Bug c++/115656] [11/12/13/14/15 Regression] Templated ctor use rejected in non-deduced context if class template has template template parameter
  2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
                   ` (5 preceding siblings ...)
  2024-06-26 14:00 ` mpolacek at gcc dot gnu.org
@ 2024-06-26 19:24 ` s.murthy at outlook dot com
  6 siblings, 0 replies; 8+ messages in thread
From: s.murthy at outlook dot com @ 2024-06-26 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Sean Murthy <s.murthy at outlook dot com> ---
Additional info, just in case it helps. Either of the following changes to the
repro causes the reported error to disappear (not saying that either change is
universally acceptable, that is, they are not workarounds).

1. In class A, unconstrain the type parameter of template template parameter V,
and make no other changes anywhere else.

```
template<std::unsigned_integral U = unsigned,
         template <class> class V = dv
        >
```

2. In class A, constrain the type parameter of template template parameter V
using type_traits *and* unconstrain the type parameter of class template dv:

```
template<typename> class dv;

template<std::unsigned_integral U = unsigned,
         template <typename T> requires std::is_unsigned_v<T> class V = dv
        >
```

Furthermore, constraining the type parameter of class template dv using
type_traits instead of concepts causes *CTAD fail* for class A and non-CTAD
fail for class B (which is odd because the change has nothing to do with class
B). And these failures go back to GCC 10.1. Assuming purely C++20 issue, this
particular manifestation does not appear to be regression.

See: https://sigcpp.godbolt.org/z/79oEaG1vo

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

end of thread, other threads:[~2024-06-26 19:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-26  1:42 [Bug c++/115656] New: Templated ctor use rejected in non-deduced context if class template has template template parameter s.murthy at outlook dot com
2024-06-26  1:48 ` [Bug c++/115656] " s.murthy at outlook dot com
2024-06-26  3:57 ` s.murthy at outlook dot com
2024-06-26  4:13 ` s.murthy at outlook dot com
2024-06-26  4:26 ` s.murthy at outlook dot com
2024-06-26  7:31 ` [Bug c++/115656] [11/12/13/14/15 Regression] " rguenth at gcc dot gnu.org
2024-06-26 14:00 ` mpolacek at gcc dot gnu.org
2024-06-26 19:24 ` s.murthy at outlook 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).