我遇到了一个非常奇怪的编译错误.出于某种原因,发布的代码使用g ++(7.3.0)正确编译,而clang(7.0.0)失败:
../TemplateAlias/main.cpp:64:9: error: no matching function for call to 'freeFunc'
freeFunc(new Func, dummyField);
^~~~~~~~
../TemplateAlias/main.cpp:73:12: note: in instantiation of member function 'Helper<Traits<double, ConcreteData, ConcreteField> >::func' requested here
helper.func();
^
../TemplateAlias/main.cpp:21:13: note: candidate template ignored: deduced conflicting templates for parameter '' ('FieldData' vs. 'ConcreteData')
static void freeFunc(SomeFunc<T, FieldData>* func,
^
Run Code Online (Sandbox Code Playgroud)
两个编译器选项都设置为-std = c ++ 14
template<typename T>
struct ConcreteData
{
T data;
};
template<typename T, template<typename U> class FieldData>
struct ConcreteField
{
FieldData<T> someMember;
};
template<typename T, template<typename U> class …Run Code Online (Sandbox Code Playgroud) 我有这段代码(让我们命名它problem.cpp):
#include <string>\n\nusing str = std::wstring;\nstatic str foo(str text = str())\n{\n text.resize(4);\n return text;\n}\n\nint main()\n{\n str a = foo();\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n-O1使用C++20 一致性 ( )调用 GCC(版本 12.2.1)g++ problem.cpp -Werror -O1 -std=c++20会导致此错误:
In file included from /usr/include/features.h:490,\n from /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/x86_64-pc-linux-gnu/bits/os_defines.h:39,\n from /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/x86_64-pc-linux-gnu/bits/c++config.h:655,\n from /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/string:38,\n from problem.cpp:1:\nIn function \xe2\x80\x98wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t)\xe2\x80\x99,\n inlined from \xe2\x80\x98static constexpr std::char_traits<wchar_t>::char_type* std::char_traits<wchar_t>::copy(char_type*, const char_type*, std::size_t)\xe2\x80\x99 at /usr/lib/gcc/x86_64-pc-linux-gnu/12/include/g++-v12/bits/char_traits.h:558:16,\n inlined from \xe2\x80\x98constexpr std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&&) [with _CharT = …Run Code Online (Sandbox Code Playgroud)