public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/64446] New: Misleading error message when inheriting from a template class w/o the template params
@ 2014-12-30 15:05 petschy at gmail dot com
  2014-12-30 15:11 ` [Bug c++/64446] " petschy at gmail dot com
  2015-03-09 12:59 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: petschy at gmail dot com @ 2014-12-30 15:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64446
           Summary: Misleading error message when inheriting from a
                    template class w/o the template params
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petschy at gmail dot com

When compiling the under code, g++ gives a misleading error message:

$ g++-5.0.0 -Wall 20141230-templ_base.cpp 
20141230-templ_base.cpp:7:1: error: expected class-name before ‘{’ token

'Base' is definitely a valid class name.

The problem is that the name given is a class, but it's a template and the
template argument is missing.

However, in the second case, when inheriting from Base2 and only one template
argument is given of the two, the error message is OK: wrong number of template
arguments (1, should be 2).

Something similar would be desirable in the first case, not to waste time
staring at the screen, searching for a typo in the class name and finding none.
Like '<classname> is a template but no template arguments are given'.

$ g++-5.0.0 -v
Using built-in specs.
COLLECT_GCC=g++-5.0.0
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-languages=c,c++ --disable-multilib
--program-suffix=-5.0.0
Thread model: posix
gcc version 5.0.0 20141222 (experimental) (GCC) 

4.9 and 4.8 gives the same misleading error message.

----8<----8<----8<----8<----
template<typename T>
struct Base
{
};

struct Foo : Base
{       // error: expected class-name before ‘{’ token
};

template<typename T, typename U>
struct Base2
{
};

struct Foo2 : Base2<int> // OK: wrong number of template arguments (1, should
be 2)
{       
};
>From gcc-bugs-return-471938-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Dec 30 15:08:09 2014
Return-Path: <gcc-bugs-return-471938-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 1940 invoked by alias); 30 Dec 2014 15:08:08 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 1926 invoked by uid 48); 30 Dec 2014 15:08:04 -0000
From: "mikpelinux at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/64442] -O1 modify output of a simple computation with rounding
Date: Tue, 30 Dec 2014 15:08:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c
X-Bugzilla-Version: 4.9.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mikpelinux at gmail dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-64442-4-Zz0IHEKOft@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-64442-4@http.gcc.gnu.org/bugzilla/>
References: <bug-64442-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-12/txt/msg02945.txt.bz2
Content-length: 297

https://gcc.gnu.org/bugzilla/show_bug.cgi?idd442

--- Comment #3 from Mikael Pettersson <mikpelinux at gmail dot com> ---
See PR323 and https://gcc.gnu.org/bugs/#known

You could experiment with -ffloat-store, -mpc64, or -msse2 (if your CPU
supports SSE2, which it should if it isn't ancient).


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

* [Bug c++/64446] Misleading error message when inheriting from a template class w/o the template params
  2014-12-30 15:05 [Bug c++/64446] New: Misleading error message when inheriting from a template class w/o the template params petschy at gmail dot com
@ 2014-12-30 15:11 ` petschy at gmail dot com
  2015-03-09 12:59 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: petschy at gmail dot com @ 2014-12-30 15:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from petschy at gmail dot com ---
One subtlety:

template<typename T=void>
struct Base3
{
};
struct Foo3 : Base3 
{
};

In this case complaining about missing template params is probably
inappropriate, since Base3<> is perfectly valid.

So on second thought, the error should be about the missing <> after the class
name.


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

* [Bug c++/64446] Misleading error message when inheriting from a template class w/o the template params
  2014-12-30 15:05 [Bug c++/64446] New: Misleading error message when inheriting from a template class w/o the template params petschy at gmail dot com
  2014-12-30 15:11 ` [Bug c++/64446] " petschy at gmail dot com
@ 2015-03-09 12:59 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-09 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-09
     Ever confirmed|0                           |1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to petschy from comment #0)
> 'Base' is definitely a valid class name.

No it isn't, Base is a class template, and that is not a class. The error
message is completely accurate, although it could be improved to say how to fix
the code.


Clang also says:

p.cc:6:14: error: expected class name
struct Foo : Base
             ^


EDG gives a better error:

"p.cc", line 6: error: argument list for class template "Base" is missing
  struct Foo : Base
               ^

"p.cc", line 6: error: not a class or struct name
  struct Foo : Base
               ^


Ideally the compiler would recognise that Base is a template and point out that
the template argument list is missing.


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

end of thread, other threads:[~2015-03-09 12:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-30 15:05 [Bug c++/64446] New: Misleading error message when inheriting from a template class w/o the template params petschy at gmail dot com
2014-12-30 15:11 ` [Bug c++/64446] " petschy at gmail dot com
2015-03-09 12:59 ` redi 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).