public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101435] New: Bad error with missing typename keyword
@ 2021-07-13 10:57 tobi at gcc dot gnu.org
  2021-07-13 11:02 ` [Bug c++/101435] " tobi at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: tobi at gcc dot gnu.org @ 2021-07-13 10:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101435
           Summary: Bad error with missing typename keyword
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tobi at gcc dot gnu.org
  Target Milestone: ---

Consider (https://godbolt.org/z/hxnv779Tr):
===================================

template<typename U, int dim>
class X {
    public:
    U v;

    using Scalar = U;
    static constexpr auto Dim = dim;

    explicit X(U x) : v(x) {}

    template<typename T>
    X<T, dim> cast()
    {
        return X<T, dim>(T{v});
    }
};

void f(int err) {
    auto propertyHelper = [err]<typename  M>(M&& fallback) -> M {
        using FloatM = X<float, M::Dim>;
        FloatM v{0};
        return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
    };
}
================================
This gives the fairly confusing error messages:
+++++++++++++++++++++++++++++++
<source>: In lambda function:
<source>:23:28: error: expected primary-expression before '{' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                            ^
<source>:23:28: error: expected ':' before '{' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                            ^
      |                            :
<source>:23:28: error: expected primary-expression before '{' token
<source>:23:28: error: expected ';' before '{' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                            ^
      |                            ;
<source>:23:55: error: expected '(' before '>' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                                                       ^
      |                                                       (
<source>:23:57: error: expected primary-expression before ')' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                                                         ^
<source>:23:58: error: expected ';' before '}' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                                                          ^~
      |                                                          ;
<source>:23:61: error: expected primary-expression before ':' token
   23 |         return err == 0 ? M{ v.cast<typename M::Scalar>() } : fallback;
      |                                                             ^
Compiler returned: 1
+++++++++++++++++++++++++++++++

The actual cause of the error is the missing typename keyword before M (clang
points this out correctly, MSVC of course accepts the code without error
message).  This is similar to #63392 but in that case we at least get a hint as
to what the actual problem is.

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

* [Bug c++/101435] Bad error with missing typename keyword
  2021-07-13 10:57 [Bug c++/101435] New: Bad error with missing typename keyword tobi at gcc dot gnu.org
@ 2021-07-13 11:02 ` tobi at gcc dot gnu.org
  2021-07-13 12:10 ` redi at gcc dot gnu.org
  2021-07-14  1:56 ` [Bug c++/101435] Bad error with missing template keyword tobi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: tobi at gcc dot gnu.org @ 2021-07-13 11:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Tobias Schlüter <tobi at gcc dot gnu.org> ---
Grrr, I made a mistake in describing the issue with the code: what is missing
is the `template` keyword before `cast`, so it should read
     return err == 0 ? M{ v.template cast<typename M::Scalar>() } : fallback;
                            ^^^^^^^^^
Of course GCC gives errors everywhere but there :D

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

* [Bug c++/101435] Bad error with missing typename keyword
  2021-07-13 10:57 [Bug c++/101435] New: Bad error with missing typename keyword tobi at gcc dot gnu.org
  2021-07-13 11:02 ` [Bug c++/101435] " tobi at gcc dot gnu.org
@ 2021-07-13 12:10 ` redi at gcc dot gnu.org
  2021-07-14  1:56 ` [Bug c++/101435] Bad error with missing template keyword tobi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2021-07-13 12:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-07-13
           Keywords|                            |diagnostic
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=16233

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Right, "typename M" would be invalid, you only need "typename" before a nested
name like M::Scalar, where M is dependent. This is nothing to do with PR 63392.

Confirmed as a diagnostic bug. It would be good to get a fix-it here. Maybe a
dup of PR 16233.

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

* [Bug c++/101435] Bad error with missing template keyword
  2021-07-13 10:57 [Bug c++/101435] New: Bad error with missing typename keyword tobi at gcc dot gnu.org
  2021-07-13 11:02 ` [Bug c++/101435] " tobi at gcc dot gnu.org
  2021-07-13 12:10 ` redi at gcc dot gnu.org
@ 2021-07-14  1:56 ` tobi at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: tobi at gcc dot gnu.org @ 2021-07-14  1:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Tobias Schlüter <tobi at gcc dot gnu.org> ---
Thank you!  I would certainly have found the other bug had I put the right
keyword into the title of the PR myself ...

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

end of thread, other threads:[~2021-07-14  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 10:57 [Bug c++/101435] New: Bad error with missing typename keyword tobi at gcc dot gnu.org
2021-07-13 11:02 ` [Bug c++/101435] " tobi at gcc dot gnu.org
2021-07-13 12:10 ` redi at gcc dot gnu.org
2021-07-14  1:56 ` [Bug c++/101435] Bad error with missing template keyword tobi 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).