[Bug c++/51665] New: undefined reference when passing static const int member to template method

2011-12-23 Thread gcc-bugzilla at bluespirit dot la
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 
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 );
}


[Bug c++/51665] undefined reference when passing static const int member to template method

2011-12-23 Thread gcc-bugzilla at bluespirit dot la
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51665

--- Comment #1 from Karl Krach  2011-12-23 
13:38:22 UTC ---
g++ *.cpp --save-temps
MyClass.o:MyClass.cpp:function MyClass::doSomething(): error: undefined
reference to 'MyClass::M_SOME_CONSTANT'
collect2: ld returned 1 exit status