public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition
@ 2004-08-24 12:41 guillaume dot melquiond at ens-lyon dot fr
  2004-08-24 12:49 ` [Bug c++/17166] " guillaume dot melquiond at ens-lyon dot fr
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2004-08-24 12:41 UTC (permalink / raw)
  To: gcc-bugs

When compiling the help.cpp file from Wesnoth CVS, both g++ 3.4.1 and 3.5 aren't
able to compile the following line. Previous versions of GCC and other compilers
don't have any problem with it.

show_info_about.erase(std::remove(show_info_about.begin(),
show_info_about.end(), gamemap::VOID_TERRAIN), show_info_about.end());

Here g++ seems to believe that the function std::remove is remove(const char *)
(file removal of the standard library). It doesn't see the stl_algo.h function.

help.cpp: In function `std::vector<help::topic, std::allocator<help::topic> >
help::generate_terrains_topics()':
help.cpp:849: error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::vector<char, std::allocator<char> > >' to `const char*' for argument `1' to
`int remove(const char*)'

However, the funny thing is that if I add the following lines just before, g++
compiles just fine the file.

typedef __typeof__ show_info_about.begin() iterator;
typedef __typeof__ gamemap::VOID_TERRAIN element;
iterator (*f)(iterator, iterator, element const &) = std::remove< iterator,
element >;

Please note that I don't use f afterwards. They really are dummy lines, f is
only here to verify that the remove function exists. And now g++ has suddenly
remembered that there is a std::remove with three arguments and it is now able
to find it at the next line.

$ LANG=C g++-3.4 -v
Reading specs from /usr/lib/gcc/i486-linux/3.4.1/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm
--enable-java-awt=gtk --disable-werror i486-linux
Thread model: posix
gcc version 3.4.1 (Debian 3.4.1-7)

$ g++-3.5 -v
Reading specs from /usr/lib/gcc/i486-linux/3.5.0/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc
--prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.5
--enable-shared --with-system-zlib --enable-nls --enable-threads=posix
--without-included-gettext --program-suffix=-3.5 --enable-__cxa_atexit
--enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug
--enable-java-gc=boehm --enable-java-awt=gtk i486-linux
Thread model: posix
gcc version 3.5.0 20040724 (experimental) (Debian 3.5-0pre1)

$ g++-3.5 -c bug.ii
help.cpp: In function `std::vector<help::topic, std::allocator<help::topic> >
help::generate_terrains_topics()':
help.cpp:849: error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::vector<char, std::allocator<char> > >' to `const char*' for argument `1' to
`int remove(const char*)'
help.cpp:851: error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::vector<char, std::allocator<char> > >' to `const char*' for argument `1' to
`int remove(const char*)'

Sorry for the huge test-case. I may try to reduce it later. Since it is that
big, I don't provide the modified file with the three dummy lines. However I
have verified that adding them to line 48553 of the preprocessed file is enough
for g++ 3.4.1 and 3.5 to compile the file successfuly.

-- 
           Summary: g++ 3.4.1 and 3.5 forget a template function definition
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: guillaume dot melquiond at ens-lyon dot fr
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
@ 2004-08-24 12:49 ` guillaume dot melquiond at ens-lyon dot fr
  2004-08-24 13:33 ` bangerth at dealii dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2004-08-24 12:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From guillaume dot melquiond at ens-lyon dot fr  2004-08-24 12:49 -------
Bugzilla complains each time I'm trying to attach the test-case. So here is an URL.

http://perso.ens-lyon.fr/guillaume.melquiond/divers/bug.ii.bz2

Sorry for the inconvenience.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
  2004-08-24 12:49 ` [Bug c++/17166] " guillaume dot melquiond at ens-lyon dot fr
@ 2004-08-24 13:33 ` bangerth at dealii dot org
  2004-08-24 13:48 ` bangerth at dealii dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2004-08-24 13:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-24 13:33 -------
Created an attachment (id=6984)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6984&action=view)
Preprocessed sources

I attach the preprocessed sources, with #line directives removed.
W.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
  2004-08-24 12:49 ` [Bug c++/17166] " guillaume dot melquiond at ens-lyon dot fr
  2004-08-24 13:33 ` bangerth at dealii dot org
@ 2004-08-24 13:48 ` bangerth at dealii dot org
  2004-08-24 14:07 ` reichelt at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2004-08-24 13:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-24 13:48 -------
Here is a redux: 
----------------- 
#include <vector> 
#include <algorithm> 
 
enum {C = ' '}; 
 
void foo() { 
  std::vector<char> show_info_about; 
  std::vector<char>::iterator 
    b = show_info_about.begin(), 
    e = show_info_about.end(); 
  std::remove(b, e, C); 
} 
------------------------ 
(Note that in the original testcase, gamemap::TERRAIN is char, and  
gamemap::VOID_TERRAIN is of enum type.) 
 
This doesn't compile with 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc  
x.cc: In function `void foo()': 
x.cc:11: error: cannot convert `__gnu_cxx::__normal_iterator<char*, 
std::vector<char, std::allocator<char> > >' to `const char*' for argument `1' 
to `int remove(const char*)' 
 
I am presently surprised that we don't match the std::remove (It, It, _T) 
template, and that the compiler rather wants to do the stdio remove(char*) 
function instead. icc compiles this cleanly. 
 
Maybe someone else wants to comment, I have too much to do today to 
investigate this fully. 
 
W. 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (2 preceding siblings ...)
  2004-08-24 13:48 ` bangerth at dealii dot org
@ 2004-08-24 14:07 ` reichelt at gcc dot gnu dot org
  2004-08-24 14:28 ` guillaume dot melquiond at ens-lyon dot fr
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-08-24 14:07 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2004-08-24 14:06 -------
It's a little complicated, but IMHO g++ behaves right:
Everything boils down to the following:

=====================================================
#include<vector>
#include<algorithm>

enum { FOGGED = '~' };

void foo()
{
    std::vector<char> v;
    std::remove(v.begin(), v.end(), FOGGED);
}
=====================================================

Compiling this I get:

  bug.cc: In function `void foo()':
  bug.cc:9: error: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::vector<char, std::allocator<char> > >' to `const char*' for argument `1' to
`int remove(const char*)'

The point is that FOGGED is from an anonymous enum which can't be a
template parameter. Just give a name to the enum, and it works fine:

  enum E { FOGGED = '~' };

Alternatively you can make a cast to something with a name:

  std::remove(v.begin(), v.end(), (char)FOGGED);


Your suggestion unexpectedly works in a similar way. By writing
    typedef __typeof__ FOGGED element;
the enum gets a name and the code can be compiled:

=====================================================
#include<vector>
#include<algorithm>

enum { FOGGED = '~' };

void foo()
{
    std::vector<char> v;
    typedef __typeof__ FOGGED element;
    std::remove(v.begin(), v.end(), FOGGED);
}
=====================================================

In essence, g++ is right IMHO, but the error message isn't very helpful...


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |reichelt at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (3 preceding siblings ...)
  2004-08-24 14:07 ` reichelt at gcc dot gnu dot org
@ 2004-08-24 14:28 ` guillaume dot melquiond at ens-lyon dot fr
  2004-08-24 18:26 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2004-08-24 14:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From guillaume dot melquiond at ens-lyon dot fr  2004-08-24 14:28 -------
Thanks a lot, giving a dummy name to the enum indeed fixes the problem.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] g++ 3.4.1 and 3.5 forget a template function definition
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (4 preceding siblings ...)
  2004-08-24 14:28 ` guillaume dot melquiond at ens-lyon dot fr
@ 2004-08-24 18:26 ` bangerth at dealii dot org
  2004-10-28  3:58 ` [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads giovannibajo at libero dot it
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: bangerth at dealii dot org @ 2004-08-24 18:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-08-24 18:26 -------
With Volker's analysis, this is the minimal testcase: 
-------------- 
template <typename T> int foo (T); 
enum {e}; 
int i = foo(e); 
-------------- 
g/x> /home/bangerth/bin/gcc-3.4-pre/bin/c++ -c x.cc 
x.cc:3: error: no matching function for call to `foo(<anonymous enum>)' 
 
Giving the enum a name makes the compiler accept the code. 
 
The question here, I guess, is this: if unnamed enums can't be template 
arguments, what does this imply? Is this a substitution failure that leads 
to the silent removal of said function from the overload set? This is how 
gcc treats things. Or should this lead to some kind of error message? The 
normative sentence 14.3.1/2 doesn't state this and I can't find any other 
sentence at present. 
 
W. 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (5 preceding siblings ...)
  2004-08-24 18:26 ` bangerth at dealii dot org
@ 2004-10-28  3:58 ` giovannibajo at libero dot it
  2005-05-29 16:03 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: giovannibajo at libero dot it @ 2004-10-28  3:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-10-28 03:58 -------
No, this is not a substitution failure, but rather a deduction failure. We 
cannot deduce the enum from the function call because it is not a valid non-
type template parameter.

What is questionable here is the error message GCC produce. I have been 
wondering for a while what is the best solution -- to me, it looks like we 
should always list the overloads we rejects, with a brief motivation of why 
they got rejected. I guess this would help tremendously.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at libero dot
                   |                            |it
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |diagnostic
   Last reconfirmed|0000-00-00 00:00:00         |2004-10-28 03:58:46
               date|                            |
            Summary|g++ 3.4.1 and 3.5 forget a  |Improve diagnostic for empty
                   |template function definition|overload set listing the
                   |                            |rejected overloads


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (6 preceding siblings ...)
  2004-10-28  3:58 ` [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads giovannibajo at libero dot it
@ 2005-05-29 16:03 ` pinskia at gcc dot gnu dot org
  2005-05-29 16:21 ` pinskia at gcc dot gnu dot org
  2005-05-29 20:45 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-29 16:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-29 16:02 -------
The testcase really boils down to:
template <typename T> int foo ();
int i = foo(1);


OR

template <typename T> struct f{};
template <typename T> int foo (f<T>);
int i = foo(1);


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2004-10-28 03:58:46         |2005-05-29 16:02:02
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (7 preceding siblings ...)
  2005-05-29 16:03 ` pinskia at gcc dot gnu dot org
@ 2005-05-29 16:21 ` pinskia at gcc dot gnu dot org
  2005-05-29 20:45 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-29 16:21 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-29 16:02 -------
*** Bug 21808 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |veksler at il dot ibm dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads
  2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
                   ` (8 preceding siblings ...)
  2005-05-29 16:21 ` pinskia at gcc dot gnu dot org
@ 2005-05-29 20:45 ` pinskia at gcc dot gnu dot org
  9 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-29 20:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-29 20:37 -------
*** Bug 21808 has been marked as a duplicate of this bug. ***

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

* [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads
       [not found] <bug-17166-4@http.gcc.gnu.org/bugzilla/>
@ 2013-06-21 14:49 ` paolo.carlini at oracle dot com
  0 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-06-21 14:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|gcc-bugs at gcc dot gnu.org        |
      Known to work|                            |4.8.0, 4.9.0
         Resolution|---                         |FIXED

--- Comment #12 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Lately the diagnostic is good.


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

* [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads
       [not found] <bug-17166-7904@http.gcc.gnu.org/bugzilla/>
@ 2005-11-25  8:31 ` guillaume dot melquiond at ens-lyon dot fr
  0 siblings, 0 replies; 13+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2005-11-25  8:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from guillaume dot melquiond at ens-lyon dot fr  2005-11-25 08:31 -------
Your testcases are too minimal. The issue lies in the diagnostic, when there is
a compilation error involving an anonymous enumeration. In the original
bug-report, GCC was trying to delete a file instead of removing a vector range.
Since the code was using a common STL idiom, it was really puzzling.

So the minimal testcase is imo this one:

struct A {};
int foo(A);
template <typename T> int foo(void *, T);
enum {e};
int i = foo(0, e);

GCC silently ignores the usually-match-anything template function and it tries
to use instead another function. Please note that this other function does not
even have the correct number of arguments! This is the error message of GCC
3.4.5 and 4.0.2:

error: conversion from 'int' to non-scalar type 'A' requested

With a snapshot of GCC 4.1, the error message is a bit better, since GCC now
gives the signatures instead of simply telling it tried to use a function of
the wrong arity:

error: no matching function for call to 'foo(int, <anonymous enum>)'
note: candidates are: int foo(A)

In particular, GCC 4.1 explicitly displays "<anonymous enum>" now. I am not
sure it is clear enough for the casual user, but at least for me it is.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17166


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

end of thread, other threads:[~2013-06-21 14:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-24 12:41 [Bug c++/17166] New: g++ 3.4.1 and 3.5 forget a template function definition guillaume dot melquiond at ens-lyon dot fr
2004-08-24 12:49 ` [Bug c++/17166] " guillaume dot melquiond at ens-lyon dot fr
2004-08-24 13:33 ` bangerth at dealii dot org
2004-08-24 13:48 ` bangerth at dealii dot org
2004-08-24 14:07 ` reichelt at gcc dot gnu dot org
2004-08-24 14:28 ` guillaume dot melquiond at ens-lyon dot fr
2004-08-24 18:26 ` bangerth at dealii dot org
2004-10-28  3:58 ` [Bug c++/17166] Improve diagnostic for empty overload set listing the rejected overloads giovannibajo at libero dot it
2005-05-29 16:03 ` pinskia at gcc dot gnu dot org
2005-05-29 16:21 ` pinskia at gcc dot gnu dot org
2005-05-29 20:45 ` pinskia at gcc dot gnu dot org
     [not found] <bug-17166-7904@http.gcc.gnu.org/bugzilla/>
2005-11-25  8:31 ` guillaume dot melquiond at ens-lyon dot fr
     [not found] <bug-17166-4@http.gcc.gnu.org/bugzilla/>
2013-06-21 14:49 ` paolo.carlini at oracle 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).