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

             Bug #: 51665
           Summary: undefined reference when passing static const int
                    member to template method
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: gcc-bugzi...@bluespirit.la


Created attachment 26172
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26172
sources, save-temps, command line

Calling the template method qMax(T,T) with a constant (static const int) as
first parameter, I get an undefined reference. When saving this constant to a
local constant and using this for as template parameter, everything works fine.

Using Debian testing with Gcc 4.6.2-7 on Linux 3.1.0.1-686-pae.

Command line: g++ *.cpp

ld --version: GNU ld (GNU Binutils for Debian) 2.22
g++ --version: g++ (Debian 4.6.2-7) 4.6.2




template <typename T>
inline const T &qMax(const T &a, const T &b) { if (a < b) return b; return a; }

class MyClass
{
public:
    void doSomething();
private:
    static const int M_SOME_CONSTANT = 24;
};


//
// NOT WORKING
//
void MyClass::doSomething()
{
    int iValue = 77 + M_SOME_CONSTANT;
    iValue += qMax( M_SOME_CONSTANT, 12 );
}

//
// WORKING
//
void MyClass::doSomething()
{
    int iValue = 77 + M_SOME_CONSTANT;
    const int iTmp = M_SOME_CONSTANT;
    iValue += qMax( iTmp , 12 );
}

Reply via email to