public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type
@ 2023-11-17 17:36 mital at mitalashok dot co.uk
  2023-11-20  5:05 ` [Bug c++/112594] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mital at mitalashok dot co.uk @ 2023-11-17 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112594
           Summary: Non-type template parameter created with converting
                    constructor sometimes has original type
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mital at mitalashok dot co.uk
  Target Milestone: ---

The following code complains that `N` (which was declared `n N`) is `3` (of
type `int`) instead of `n(3)`:

<https://godbolt.org/z/rv3777Ycv>

    template<typename T>
    concept C = true;

    struct n {
        constexpr n(int) {}
        static int i;
    };

    template<n N>
    using get_n_i_type = decltype(N.i);

    template<int X>
    int f() {
        using iii = get_n_i_type<X>;
    #if 1  // Change to 0 and this compiles
        static_assert(C<iii>);
    #endif
        return iii{};
    }

    template int f<3>();

Compiler error given:

    <source>: In instantiation of 'int f() [with int X = 3]':
    <source>:21:19:   required from here
       21 | template int f<3>();
          |                   ^
    <source>:10:33: error: request for member 'i' in '3', which is of non-class
type 'int'
       10 | using get_n_i_type = decltype(N.i);
          |                               ~~^

This compiles fine if Clang and MSVC or if you remove the static_assert or
change `template<int X>` to `template<auto X>`.

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 17:36 [Bug c++/112594] New: Non-type template parameter created with converting constructor sometimes has original type mital at mitalashok dot co.uk
2023-11-20  5:05 ` [Bug c++/112594] " pinskia at gcc dot gnu.org
2023-11-20  5:09 ` pinskia at gcc dot gnu.org
2024-01-19 18:35 ` cvs-commit at gcc dot gnu.org
2024-01-19 18:37 ` jason 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).