public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17344] New: spurious error
@ 2004-09-07 10:07 igodard at pacbell dot net
  2004-09-07 10:08 ` [Bug c++/17344] " igodard at pacbell dot net
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: igodard at pacbell dot net @ 2004-09-07 10:07 UTC (permalink / raw)
  To: gcc-bugs

The error reported in the example is bogus; there is no error. After sleuthing, 
it turns out that the report goes away if a particular copy constrictor in an 
unrelated and unused other class is removed. In the sample code attached, search for "COMMENT OUT NEXT LINE" and comment out the following line and the code will compile OK. Any significant simplication also seems to make the problem go away too. Note that the problem-causing constructor is in a template class that is never used, while the reported error is elsewhere completely.

BTW, a caution: this looks to me like some compiler internal structure is being overwritten. Consequently it is likely that the bug will disappear or show up differently in any other compiler version. So if it doesn't show on 5.0, please don't assume it's been fixed; much more likely is that it has simply been hidden by internal compiler remappings, and when you find the problem in 4.0 and look in the code of 5.0 etc you will find the bug is still there, just displayed differently. The voice of experience :-)

Ivan

-- 
           Summary: spurious error
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug c++/17344] spurious error
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
@ 2004-09-07 10:08 ` igodard at pacbell dot net
  2004-09-07 10:09 ` igodard at pacbell dot net
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: igodard at pacbell dot net @ 2004-09-07 10:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2004-09-07 10:08 -------
Created an attachment (id=7060)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7060&action=view)
Compiler output (-v -save-temps)


-- 


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


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

* [Bug c++/17344] spurious error
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
  2004-09-07 10:08 ` [Bug c++/17344] " igodard at pacbell dot net
@ 2004-09-07 10:09 ` igodard at pacbell dot net
  2004-09-08  5:31 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: igodard at pacbell dot net @ 2004-09-07 10:09 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From igodard at pacbell dot net  2004-09-07 10:09 -------
Created an attachment (id=7061)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7061&action=view)
Source code (-save-temps)


-- 


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


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

* [Bug c++/17344] spurious error
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
  2004-09-07 10:08 ` [Bug c++/17344] " igodard at pacbell dot net
  2004-09-07 10:09 ` igodard at pacbell dot net
@ 2004-09-08  5:31 ` pinskia at gcc dot gnu dot org
  2004-09-16 15:44 ` bangerth at dealii dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-08  5:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-08 05:31 -------
Note there are more errors on the mainline:
In file included from /home/ivan/ootbc/common/include/bitset.hh:92,
                 from opSet.cc:2:
/home/ivan/ootbc/common/include/row.hh: In member function `size_t row<void>::max_size() 
const':
/home/ivan/ootbc/common/include/row.hh:1311: warning: converting of negative value 
`-0x000000001' to `size_t'
In file included from opSet.cc:3:
/home/ivan/ootbc/common/include/pile.hh: In destructor `pileBase::~pileBase()':
/home/ivan/ootbc/common/include/pile.hh:125: error: ISO C++ says that these are ambiguous, even 
though the worst conversion for the first is better than the worst conversio
n for the second:
/home/ivan/ootbc/common/include/comtype.hh:264: note: candidate 1: bool operator!=(const T*, 
nil_t) [with T = block]
/home/ivan/ootbc/common/include/pile.hh:125: note: candidate 2: operator!=(block*, block*) <built-
in>
/home/ivan/ootbc/common/include/pile.hh:130: error: ISO C++ says that these are ambiguous, even 
though the worst conversion for the first is better than the worst conversio
n for the second:
/home/ivan/ootbc/common/include/comtype.hh:264: note: candidate 1: bool operator!=(const T*, 
nil_t) [with T = block]
/home/ivan/ootbc/common/include/pile.hh:130: note: candidate 2: operator!=(block*, block*) <built-
in>
opSet.cc: At global scope:
opSet.cc:5: error: ISO C++ says that these are ambiguous, even though the worst conversion for the 
first is better than the worst conversion for the second:
opSet.cc:5: note: candidate 1: operator-(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:113: note: candidate 2: T operator-(T, Arg) [with Arg = 
A, T = element<unsigned char>]
opSet.cc:5: error: ISO C++ says that these are ambiguous, even though the worst conversion for the 
first is better than the worst conversion for the second:
opSet.cc:5: note: candidate 1: operator-(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:113: note: candidate 2: T operator-(T, Arg) [with Arg = 
A, T = element<int>]
opSet.cc:5: error: ISO C++ says that these are ambiguous, even though the worst conversion for the 
first is better than the worst conversion for the second:
opSet.cc:5: note: candidate 1: operator-(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:113: note: candidate 2: T operator-(T, Arg) [with Arg = 
A, T = element<signed char>]
/home/ivan/ootbc/common/include/bitset.hh: In instantiation of `bitset<A, B, C>':
opSet.cc:8:   instantiated from here
/home/ivan/ootbc/common/include/bitset.hh:315: error: ISO C++ says that these are ambiguous, 
even though the worst conversion for the first is better than the worst convers
ion for the second:
/home/ivan/ootbc/common/include/bitset.hh:315: note: candidate 1: operator-(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:113: note: candidate 2: T operator-(T, Arg) [with Arg = 
A, T = element<unsigned char>]
/home/ivan/ootbc/common/include/bitset.hh:315: error: ISO C++ says that these are ambiguous, 
even though the worst conversion for the first is better than the worst convers
ion for the second:
/home/ivan/ootbc/common/include/bitset.hh:315: note: candidate 1: operator-(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:113: note: candidate 2: T operator-(T, Arg) [with Arg = 
A, T = element<int>]
/home/ivan/ootbc/common/include/bitset.hh:315: error: ISO C++ says that these are ambiguous, 
even though the worst conversion for the first is better than the worst convers
ion for the second:
/home/ivan/ootbc/common/include/bitset.hh:315: note: candidate 1: operator-(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:113: note: candidate 2: T operator-(T, Arg) [with Arg = 
A, T = element<signed char>]
/home/ivan/ootbc/common/include/bitset.hh:323: error: ISO C++ says that these are ambiguous, 
even though the worst conversion for the first is better than the worst convers
ion for the second:
/home/ivan/ootbc/common/include/bitset.hh:323: note: candidate 1: operator+(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:101: note: candidate 2: T operator+(Arg, const T&) 
[with Arg = A, T = element<unsigned char>]
/home/ivan/ootbc/common/include/bitset.hh:323: error: ISO C++ says that these are ambiguous, 
even though the worst conversion for the first is better than the worst convers
ion for the second:
/home/ivan/ootbc/common/include/bitset.hh:323: note: candidate 1: operator+(int, int) <built-in>
/home/ivan/ootbc/common/include/mixin.hh:101: note: candidate 2: T operator+(Arg, const T&) 
[with Arg = A, T = element<int>]
/home/ivan/ootbc/common/include/bitset.hh:323: error: ISO C++ says that these are ambiguous, 
even though the worst conversion for the first is better than the worst convers
....

Maybe those are errors are related or not.

-- 


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


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

* [Bug c++/17344] spurious error
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2004-09-08  5:31 ` pinskia at gcc dot gnu dot org
@ 2004-09-16 15:44 ` bangerth at dealii dot org
  2004-09-16 16:18 ` [Bug c++/17344] completely wacky error with matching template template classes and default arguments bangerth at dealii dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-09-16 15:44 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-09-16 15:44 -------
About the unrelatedness of some text: when I replace the definition 
of class pile and everything below by this code 
----------------- 
struct pile: public equalityMixin<pile> 
{ 
    template<template<typename>class raw> 
    pile(const raw<void>& r) : base(pileBase::init(r)) {} 
 
    pile(const pile& p) : base(p.base) {} 
    pileBase& base; 
 }; 
 
 
void foo() { 
 bitset<int, 1, 2> bed; 
 bed != bed; 
 } 
---------------------- 
then I still see the problem. This comes from the fact that the operator 
!= you want to call is injected by the class equalityMixin, which is 
instantiated by the declaration of class pile. If you don't declare this 
class, then we have one less overload. As to why we get the error 
I don't know yet. 
 
W. 

-- 


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2004-09-16 15:44 ` bangerth at dealii dot org
@ 2004-09-16 16:18 ` bangerth at dealii dot org
  2004-09-16 16:22 ` bangerth at dealii dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-09-16 16:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-09-16 16:17 -------
Alright, this is completely bizarre: 
------------------------ 
template <class> struct intTraits {}; 
 
template<> struct intTraits<int> { 
    static const int i = 0; 
}; 
 
template <typename T> 
struct injector { 
    friend void foo (T) {}; 
}; 
 
template<typename E, E i = intTraits<E>::i> 
struct bitset : injector<bitset<E, i> > {}; 
 
struct S: injector<S> { 
    template <template <typename> class X> S(X<void>); 
}; 
 
void foo() { 
  bitset<int> bed; 
  foo(bed); 
} 
-------------------------- 
What happens is this: both struct bitset and struct S derive from  
struct injector, so that after instantiating bitset<int> we have the 
following two functions foo() in the global namespace: 
  void foo(bitset<int,0>); 
  void foo(S); 
Now, when we get to the line where we call foo(), the compiler checks out 
all members of the overload set, i.e. the two functions above. It could 
realize that it should simply call the first one because the argument is 
of type bitset<int,0>, but it also tries the second one and finds out 
the following: 
  - the argument bitset<int,0> isn't an exact match to the type "S" 
    needed for the second foo() function 
  - but, lo and behold, they may be convertible as S has a templated 
    copy constructor. So it tries whether it can match X<void> against 
    bitset<int> (remember that gcc has an extension that allows to 
    treat template classes with two template arguments of which the 
    second one has a default value just as a template class with only 
    one argument).  
  - to do that, it matches X against bitset, but then it has to 
    figure out the value of the second argument of bitset using the 
    default argument, and that means that it has to look up 
      intTraits<void> 
  - that doesn't exist, so it realizes that the second template argument 
    has an invalid valid, and thus we get this obscure error message: 
    g/x> /home/bangerth/bin/gcc-4.0-pre/bin/c++ -c x.cc 
    x.cc: In function `void foo()': 
    x.cc:21: error: template argument 2 is invalid 
 
This is certainly one of the most amusing PRs I've seen in a while :-) 
 
Note that gcc2.95 through 3.3.x had slightly better error messages: 
g/x> /home/bangerth/bin/gcc-2*/bin/c++ -c x.cc 
x.cc: In function `void foo()': 
x.cc:21: `i' is not a member of type `intTraits<void>' 
x.cc:21: template argument 2 is invalid 
 
At least it hinted at intTraits<void> although it is of course completely 
nonobvious why it is even looking at that class. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-09-16 16:17:50
               date|                            |
            Summary|spurious error              |completely wacky error with
                   |                            |matching template template
                   |                            |classes and default
                   |                            |arguments


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (4 preceding siblings ...)
  2004-09-16 16:18 ` [Bug c++/17344] completely wacky error with matching template template classes and default arguments bangerth at dealii dot org
@ 2004-09-16 16:22 ` bangerth at dealii dot org
  2004-09-16 16:31 ` bangerth at dealii dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-09-16 16:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-09-16 16:22 -------
Given my explanation, one can of course omit the friend function 
injection: 
-------------------- 
template <class> struct intTraits; 
 
template<> struct intTraits<int> { 
    static const int i = 0; 
}; 
 
template<typename E, E i = intTraits<E>::i> struct A {}; 
 
struct S { 
    template <template <typename> class X> S(X<void>); 
}; 
 
int bar(S); 
int bar(A<int,0>); 
 
A<int> bed; 
int i = bar(bed); 
----------------------- 
 
g/x> /home/bangerth/bin/gcc-4.0-pre/bin/c++ -c x.cc 
x.cc:17: error: template argument 2 is invalid 
 
W. 

-- 


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (5 preceding siblings ...)
  2004-09-16 16:22 ` bangerth at dealii dot org
@ 2004-09-16 16:31 ` bangerth at dealii dot org
  2004-11-12 14:51 ` lerdsuwa at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-09-16 16:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-09-16 16:31 -------
I have just filed aAspinoff of this one as PR 17524. 
W. 

-- 


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (6 preceding siblings ...)
  2004-09-16 16:31 ` bangerth at dealii dot org
@ 2004-11-12 14:51 ` lerdsuwa at gcc dot gnu dot org
  2004-11-14 10:57 ` cvs-commit at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-11-12 14:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From lerdsuwa at gcc dot gnu dot org  2004-11-12 14:51 -------
Got it.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |lerdsuwa at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (7 preceding siblings ...)
  2004-11-12 14:51 ` lerdsuwa at gcc dot gnu dot org
@ 2004-11-14 10:57 ` cvs-commit at gcc dot gnu dot org
  2004-11-14 10:59 ` lerdsuwa at gcc dot gnu dot org
  2004-12-17  0:13 ` bangerth at dealii dot org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-11-14 10:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-11-14 10:57 -------
Subject: Bug 17344

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	lerdsuwa@gcc.gnu.org	2004-11-14 10:57:00

Modified files:
	gcc/cp         : ChangeLog pt.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: defarg5.C 

Log message:
	PR c++/17344
	* pt.c (coerce_template_parms): Only emit error message about
	invalid template argument when TF_ERROR.
	
	* g++.dg/template/defarg5.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4481&r2=1.4482
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.945&r2=1.946
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4595&r2=1.4596
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/defarg5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (8 preceding siblings ...)
  2004-11-14 10:57 ` cvs-commit at gcc dot gnu dot org
@ 2004-11-14 10:59 ` lerdsuwa at gcc dot gnu dot org
  2004-12-17  0:13 ` bangerth at dealii dot org
  10 siblings, 0 replies; 12+ messages in thread
From: lerdsuwa at gcc dot gnu dot org @ 2004-11-14 10:59 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From lerdsuwa at gcc dot gnu dot org  2004-11-14 10:59 -------
Fixed in the mainline by patch:
  http://gcc.gnu.org/ml/gcc-patches/2004-11/msg01152.html

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


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


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

* [Bug c++/17344] completely wacky error with matching template template classes and default arguments
  2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
                   ` (9 preceding siblings ...)
  2004-11-14 10:59 ` lerdsuwa at gcc dot gnu dot org
@ 2004-12-17  0:13 ` bangerth at dealii dot org
  10 siblings, 0 replies; 12+ messages in thread
From: bangerth at dealii dot org @ 2004-12-17  0:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From bangerth at dealii dot org  2004-12-17 00:12 -------
*** Bug 19047 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benh at bwsint dot com


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


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

end of thread, other threads:[~2004-12-17  0:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-07 10:07 [Bug c++/17344] New: spurious error igodard at pacbell dot net
2004-09-07 10:08 ` [Bug c++/17344] " igodard at pacbell dot net
2004-09-07 10:09 ` igodard at pacbell dot net
2004-09-08  5:31 ` pinskia at gcc dot gnu dot org
2004-09-16 15:44 ` bangerth at dealii dot org
2004-09-16 16:18 ` [Bug c++/17344] completely wacky error with matching template template classes and default arguments bangerth at dealii dot org
2004-09-16 16:22 ` bangerth at dealii dot org
2004-09-16 16:31 ` bangerth at dealii dot org
2004-11-12 14:51 ` lerdsuwa at gcc dot gnu dot org
2004-11-14 10:57 ` cvs-commit at gcc dot gnu dot org
2004-11-14 10:59 ` lerdsuwa at gcc dot gnu dot org
2004-12-17  0:13 ` bangerth at dealii dot 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).