2

I am having trouble with a template specialisation of a deleted template function. The code below shows the problem boiled down to a MWE:

#include <iostream>
#include <string>

template<typename T>
inline std::string typeToString() = delete;

template<>
inline std::string typeToString<float>()
{
    return "float";
}

int main()
{
    std::cout << typeToString<float>() << std::endl;
}

With gcc 7 this compiles fine. However, with Apple LLVM 8.0.0 I get the following error messages:

clang test.cpp -std=c++1z
test.cpp:8:28: error: inline declaration of 'typeToString<float>' follows non-inline definition
    inline std::string typeToString<float>()
                       ^
test.cpp:8:28: note: previous definition is here
test.cpp:15:18: error: call to deleted function 'typeToString'
std::cout << typeToString<float>() << std::endl;
             ^~~~~~~~~~~~~~~~~~~
test.cpp:8:28: note: candidate function [with T = float] has been explicitly deleted
    inline std::string typeToString<float>()
NOhs
  • 2,780
  • 3
  • 25
  • 59
  • 1
    Perhaps Apple LLVM 8.0.0 was written against an [older version of the C++11 standard](https://stackoverflow.com/a/33258249/501250) which did not permit specialization of deleted functions. Is there a newer version of this compiler that you could use? – cdhowie Jul 24 '17 at 15:33

1 Answers1

1

This looks to be a bug. If you compile with clang 3.9.1 or above it will compile. The following examples on Golbolt and Wandbox with clang 3.8.1 fail but when we change to 3.9.1 they both compile.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402