Clang 3.2 reports an error in the following code, and I do not understand why the problem occurs. The error occurs only in the template function, and only if curly braces are used for initialization. The other two initializations work as expected.
struct foo { foo() { } ~foo() = default; // deleted foo(const foo& rhs) = delete; foo(foo&& rhs) noexcept = delete; auto operator=(const foo& rhs) -> foo& = delete; auto operator=(foo&& rhs) noexcept -> foo& = delete; }; template <typename Type> void bar() { foo a; // OK foo b{}; // ERROR } int main() { foo c{}; // OK bar<int>(); }
If I compile the code using clang++ -Wall -std=c++11 -c , Clang prints the following error message:
bug.cpp:14:9: error: conversion function from 'foo' to 'foo' invokes a deleted function foo b{}; // ERROR ^ bug.cpp:19:5: note: in instantiation of function template specialization 'bar<int>' requested here bar<int>(); ^ bug.cpp:6:5: note: function has been explicitly marked deleted here foo(foo&& rhs) noexcept = delete; ^ 1 error generated.
I have no idea why Klang is trying to do the conversion. It sounds like a mistake. Unfortunately, I have a problem in a more complex code base, where the solution is not as simple as removing curly braces.
Why does the clan need a transformation in this case? And how can I make it work as a whole?
nosid source share