public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41614]  New: Compilation error with member templates
@ 2009-10-06 21:11 zhnmju123 at gmx dot de
  2009-10-07  8:46 ` [Bug c++/41614] " redi at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zhnmju123 at gmx dot de @ 2009-10-06 21:11 UTC (permalink / raw)
  To: gcc-bugs

Hi,

the following code fails to compile under MinGW (GCC 4) as well as Ubuntu Linux
(GCC 4) although it is syntactically correct:




template <bool respectFiltering>
class DetectChanges
{
public:
    template <int side>
    void detectFileChange() const {}
};

class RedetermineAuto
{
public:
    RedetermineAuto()
    {
        execute(DetectChanges<false>());
    }

private:
    template <bool dbLeftFilterActive>
    static void execute(DetectChanges<dbLeftFilterActive> dbLeft)
    {
        dbLeft.detectFileChange<3>();
    }
};


int main()
{
    return 0;
}


Compiler messages:
C:\Programme\C++\Projects\test\main.cpp|25|error: expected primary-expression
before ')' token|
C:\Programme\C++\Projects\test\main.cpp|18|instantiated from here|
C:\Programme\C++\Projects\test\main.cpp|25|error: invalid operands of types
'<unresolved overloaded function type>' and 'int' to binary 'operator<'|
||=== Build finished: 2 errors, 0 warnings ===|




If the unrelated statement "template <int> void detectFileChange();" is
inserted at the top, the code compiles which is very strange.

Regards, ZenJu


-- 
           Summary: Compilation error with member templates
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zhnmju123 at gmx dot de


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


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

* [Bug c++/41614] Compilation error with member templates
  2009-10-06 21:11 [Bug c++/41614] New: Compilation error with member templates zhnmju123 at gmx dot de
@ 2009-10-07  8:46 ` redi at gcc dot gnu dot org
  2009-10-07  9:33 ` zhnmju123 at gmx dot de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-10-07  8:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from redi at gcc dot gnu dot org  2009-10-07 08:46 -------
The code is not valid, you need to change the line with the error to:

        dbLeft.template detectFileChange<3>();


-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/41614] Compilation error with member templates
  2009-10-06 21:11 [Bug c++/41614] New: Compilation error with member templates zhnmju123 at gmx dot de
  2009-10-07  8:46 ` [Bug c++/41614] " redi at gcc dot gnu dot org
@ 2009-10-07  9:33 ` zhnmju123 at gmx dot de
  2009-10-07  9:48 ` redi at gcc dot gnu dot org
  2009-10-07 12:31 ` zhnmju123 at gmx dot de
  3 siblings, 0 replies; 5+ messages in thread
From: zhnmju123 at gmx dot de @ 2009-10-07  9:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from zhnmju123 at gmx dot de  2009-10-07 09:33 -------
Thanks for the fast reply! I had tried compilation with VC++ 2008 and there it
worked, so I thought it would be valid.
Maybe a more expressive error message could help. In this shortened example the
error message is ... well... okay, but in my reallife project I get this as a
first error, which is totally misleading (and lead me into thinking this is a
compiler bug):

C:\Programme\C++\Projects\FreeFileSync\algorithm.cpp|565|error: no match for
'operator<' in 'dbLeft->DetectChanges::detectFileChange [with
FreeFileSync::SelectedSide side = side, bool respectFiltering = true] <
(FreeFileSync::SelectedSide)0u'|
C:\Programme\C++\wxWidgets\include\wx\string.h|1572|note: candidates are: bool
operator<(const wxString&, const wxString&)|
C:\Programme\C++\wxWidgets\include\wx\string.h|1574|note:                 bool
operator<(const wxString&, const wxChar*)|
C:\Programme\C++\wxWidgets\include\wx\string.h|1576|note:                 bool
operator<(const wxChar*, const wxString&)|
C:\Programme\C++\wxWidgets\include\wx\longlong.h|1040|note:                
bool operator<(long int, const wxLongLong&)|
C:\Programme\C++\wxWidgets\include\wx\longlong.h|1053|note:                
bool operator<(long unsigned int, const wxULongLong&)|


-- 


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


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

* [Bug c++/41614] Compilation error with member templates
  2009-10-06 21:11 [Bug c++/41614] New: Compilation error with member templates zhnmju123 at gmx dot de
  2009-10-07  8:46 ` [Bug c++/41614] " redi at gcc dot gnu dot org
  2009-10-07  9:33 ` zhnmju123 at gmx dot de
@ 2009-10-07  9:48 ` redi at gcc dot gnu dot org
  2009-10-07 12:31 ` zhnmju123 at gmx dot de
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-10-07  9:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from redi at gcc dot gnu dot org  2009-10-07 09:48 -------
(In reply to comment #2)
> Thanks for the fast reply! I had tried compilation with VC++ 2008 and there it
> worked, so I thought it would be valid.

You should be wary of using VC++ to determine if code is valid, it's not often
right!

> Maybe a more expressive error message could help. In this shortened example the
> error message is ... well... okay, but in my reallife project I get this as a
> first error, which is totally misleading (and lead me into thinking this is a
> compiler bug):
> 
> C:\Programme\C++\Projects\FreeFileSync\algorithm.cpp|565|error: no match for
> 'operator<' in 'dbLeft->DetectChanges::detectFileChange [with
> FreeFileSync::SelectedSide side = side, bool respectFiltering = true] <
> (FreeFileSync::SelectedSide)0u'|
> C:\Programme\C++\wxWidgets\include\wx\string.h|1572|note: candidates are: bool
> operator<(const wxString&, const wxString&)|
> C:\Programme\C++\wxWidgets\include\wx\string.h|1574|note:                 bool
> operator<(const wxString&, const wxChar*)|
> C:\Programme\C++\wxWidgets\include\wx\string.h|1576|note:                 bool
> operator<(const wxChar*, const wxString&)|
> C:\Programme\C++\wxWidgets\include\wx\longlong.h|1040|note:                
> bool operator<(long int, const wxLongLong&)|
> C:\Programme\C++\wxWidgets\include\wx\longlong.h|1053|note:                
> bool operator<(long unsigned int, const wxULongLong&)|
> 

Although it may be confusing, the message is technically correct, due to the
complicated parsing rules of C++.

no match for
'operator<' in 'dbLeft->DetectChanges::detectFileChange [...] <
(FreeFileSync::SelectedSide)0u'

says that the expression is being interpreted as 'x < y' where x is the member
'detectFileChange' and y is an integer constant. There is no appropriate
operator< available so it lists the visible overloads of operator<

The rules of C++ specifically say that the compiler must interpret it like
that, see 14.3 [temp.names] paragraph 4. The way to resolve it is to say you
are calling a template member function, by inserting the keyword 'template'
before the template-id, as I showed.


-- 


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


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

* [Bug c++/41614] Compilation error with member templates
  2009-10-06 21:11 [Bug c++/41614] New: Compilation error with member templates zhnmju123 at gmx dot de
                   ` (2 preceding siblings ...)
  2009-10-07  9:48 ` redi at gcc dot gnu dot org
@ 2009-10-07 12:31 ` zhnmju123 at gmx dot de
  3 siblings, 0 replies; 5+ messages in thread
From: zhnmju123 at gmx dot de @ 2009-10-07 12:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from zhnmju123 at gmx dot de  2009-10-07 12:30 -------
This seems to be the member template analogon to cases where "typename" is
needed for nested types. Thanks for the detailed explanation!


-- 


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


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

end of thread, other threads:[~2009-10-07 12:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-06 21:11 [Bug c++/41614] New: Compilation error with member templates zhnmju123 at gmx dot de
2009-10-07  8:46 ` [Bug c++/41614] " redi at gcc dot gnu dot org
2009-10-07  9:33 ` zhnmju123 at gmx dot de
2009-10-07  9:48 ` redi at gcc dot gnu dot org
2009-10-07 12:31 ` zhnmju123 at gmx dot de

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).