http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60878
Bug ID: 60878
Summary: Explicit Specialization of Inner Template Class In A
Template Class, Using an Enum in Parent Template Class
as Template Argument
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fasdfasdas at gmail dot com
The following code compiles in clang++ 3.5 (as of yesterday's unstable branch)
and g++ 4.6.3. It does not compile with clang++ 2.9. It also compiles on "GNU
C++ (GCC) version 4.8.2 20140206 (prerelease) (x86_64-unknown-linux-gnu)" but
not "GNU C++ (Arch Repository) version 4.8.2 (arm-none-eabi)".
The compilers that do not compile the code gives an error saying:
test.cpp: In function 'int main()':
test.cpp:60:7: error: 'class Port<0u>::Pin<5u, (Port<0u>::PinMode)1>' has no
member named 'set'
pin.set();
^
Apparently, they do choose the class template, not the specialization.
Code to reproduce:
#include <cstdint>
template<std::size_t port>
class Port
{
public: //Declarations
enum class PinMode
{
Input = 0x0,
Output = 0x1,
Alternate = 0x2,
Analog = 0x3
};
template<uint8_t nPin, PinMode mode>
class Pin
{
};
template<uint8_t nPin>
class Pin<nPin, PinMode::Output>
{
public: //Declarations
enum class OutputSpeed : uint32_t
{
Low,
Medium,
Fast,
High
};
enum class PullMode : uint32_t
{
None = 0x0,
PullUp = 0x1,
PullDown = 0x2
};
public: //Methods
void setOutputSpeed(OutputSpeed const ospeed) volatile;
void setPullMode(PullMode const ppm) volatile;
void set() volatile
{
reinterpret_cast<Port<port> volatile*>(port)->m_BSRR |=
static_cast<uint16_t>(0x1) <<nPin;
}
void reset() volatile;
bool getOutputState() volatile;
}; //END OutputPin
public: //Registers
uint32_t m_BSRR;
}; //END Port
int main()
{
auto pin = Port<0>::Pin<5, Port<0>::PinMode::Output>();
pin.set();
}