This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16696] New: Strange message when operator++ not found


Take this: 
---------------- 
struct X { void operator++(); }; 
 
int main () { 
  X x; 
  x++; 
} 
--------------- 
Since there is indeed no postfix operator++ declared, the code is invalid, 
but we get a strange error message: 
 
g/x> /home/bangerth/tmp/gcc/b35/gcc/cc1plus -quiet -O2 xx.cc  
xx.cc: In function `int main()': 
xx.cc:5: error: no `operator++(int)' declared for postfix `++', trying prefix 
operator instead 
 
What does the compiler mean when it says "Trying prefix operator instead"? 
Does this imply that if there is one then it would use it? Hopefully not. 
However, if I remove the prefix form as well, i.e. do this: 
-------------------- 
struct X {}; 
 
int main () { 
  X x; 
  x++; 
} 
-------------------- 
then I get this instead: 
 
g/x> /home/bangerth/tmp/gcc/b35/gcc/cc1plus -quiet -O2 xx.cc  
xx.cc: In function `int main()': 
xx.cc:5: error: no `operator++(int)' declared for postfix `++', trying prefix 
operator instead 
xx.cc:5: error: no match for 'operator++' in '++x' 
 
Now, I think that's completely bogus: we do have a syntax error here, 
so why is the compiler pretending it is trying to find a way around it 
for me? If it said, as a note: 
  Note: the class declares a prefix operator++ instead 
then that would be fine, but the message that it is trying something else 
instead is too much AI for me... 
 
This behavior has been with us since at least 2.95. 
 
W.

-- 
           Summary: Strange message when operator++ not found
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bangerth at dealii dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]