clang++

Template Argument Deduction Broken in Clang 6 for Temporary Objects

浪子不回头ぞ 提交于 2019-11-28 13:32:26
Template argument deduction appears to be broken in Clang 6 for temporary objects. g++ 8.1.0 compiles and runs the example correctly. Clang 6.0.0 and 6.0.2 both error at the indicated line with this message: error: expected unqualified-id Print{1,"foo"s,2}; /********** Broken in Clang **********/ All Other lines work correctly. The behavior is the same in both cases whether -std=c++17 or -std=c++2a is used. The Clang c++ Status Page indicates that template argument deduction was implemented as of Clang 5 (P0091R3, P0512R0). Is this a bug? Are there workarounds (e.g. compiler flags, not code

Why does g++5 deduces object instead of initializer_list in auto type deduction

感情迁移 提交于 2019-11-28 12:17:24
I recently came upon this code: struct Foo{}; int main() { Foo a; // clang++ deduces std::initializer_list // g++5.1 deduces Foo auto b{a}; a = b; } It compiles fine with g++5.1, but fails in clang++ (used both -std=c++11 and -std=c++14 , same results). The reason is that clang++ deduces the type of b as std::initializer_list<Foo> , whereas g++5.1 deduces as Foo . AFAIK, the type should indeed be (counter-intuitive indeed) std::initializer_list here . Why does g++5 deduces the type as Foo ? There is a proposal for C++1z that implements new type deduction rules for brace initialization ( N3922

Using memory sanitizer with libstdc++

空扰寡人 提交于 2019-11-28 08:56:53
I wish to use the -fsanitize=memory flag in clang to analyse a program like the following: #include <string> #include <iostream> #include <fstream> using namespace std; void writeToFile(){ ofstream o; o.open("dum"); o<<"test"<<endl; //The error is here. //It does not matter if the file is opened this way, //or with o("dum"); o.close(); } int main(){ writeToFile(); } As far as I know, this program is correct, but when I use clang++ san.cpp -fsanitize=memory It fails (at runtime) with: UMR in __interceptor_write at offset 0 inside [0x64800000e000, +5) ==9685== WARNING: MemorySanitizer: use-of

Clang Compile error with default initialization [duplicate]

一个人想着一个人 提交于 2019-11-28 08:37:54
问题 This question already has answers here : Do I really need to implement user-provided constructor for const objects? (4 answers) Closed 4 years ago . Consider following example: #include <iostream> #include <type_traits> struct A { //A() = default; // does neither compile with, nor without this line //A(){}; // does compile with this line int someVal{ 123 }; void foobar( int ) { }; }; int main() { const A a; std::cout << "isPOD = " << std::is_pod<A>::value << std::endl; std::cout << "a.someVal

get<string> for variants fail under clang++ but not g++

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:57:06
问题 The following code: variant<string> x = "abc"; cout << get<string>(x) << "\n"; works fine under g++ (version 7.2). However, when compiled under clang++ (version 5.0) using libstdc++, I get the following error in the get method: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.2.0/../../../../include/c++/7.2.0/variant:238:46: fatal error: cannot cast 'std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to its private base class 'std::__detail::__variant::

g++ rejects, clang++ accepts: foo(x)(“bar”)(“baz”);

你离开我真会死。 提交于 2019-11-28 06:56:51
问题 Somebody had asked the other day why something compiles with clang, but not with gcc. I intuitively understood what was happening and was able to help the person, but it got me wondering -- according to the standard, which compiler was correct? Here is a boiled down version of the code: #include <iostream> #include <string> class foo { public: foo(const std::string& x): name(x) { } foo& operator()(const std::string& x) { std::cout << name << ": " << x << std::endl; return (*this); } std:

Parameter with non-deduced type after parameter pack

≯℡__Kan透↙ 提交于 2019-11-28 04:50:33
问题 There is different behaviour in clang++ and g++ for the next program: #include <type_traits> #include <utility> template< std::size_t index, typename type > struct ref { type & value; }; template< std::size_t index, typename type > type && get(ref< index, type > const & r) { return std::forward< type >(r.value); } template< typename F, typename ...types, std::size_t ...indices > decltype(auto) apply_inverse(F & f, types &... values, std::index_sequence< indices... >) { struct : ref< indices,

Simple std::regex_search() code won't compile with Apple clang++ -std=c++14

我们两清 提交于 2019-11-28 01:49:21
Here is the MCVE: #include <iostream> #include <regex> std::string s() { return "test"; } int main() { static const std::regex regex(R"(\w)"); std::smatch smatch; if (std::regex_search(s(), smatch, regex)) { std::cout << smatch[0] << std::endl; } return 0; } It compiles fine with: $ clang++ -std=c++11 main.cpp but not with: $ clang++ -std=c++14 main.cpp Error message in the later case (with -std=c++14): main.cpp:14:9: error: call to deleted function 'regex_search' if (std::regex_search(s(), smatch, regex)) { ^~~~~~~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault

How is P0522R0 breaking code?

こ雲淡風輕ζ 提交于 2019-11-28 00:44:08
Today I was reading the C++17 support page of clang. I've notice something odd. The feature Matching template template parameters to compatible arguments ( P0522R0 ) is marked as partial, because it must be activate through a switch. Their note says : Despite being the the resolution to a Defect Report, this feature is disabled by default in all language versions, and can be enabled explicitly with the flag -frelaxed-template-template-args in Clang 4. The change to the standard lacks a corresponding change for template partial ordering, resulting in ambiguity errors for reasonable and

Clang doesn't see basic headers

拟墨画扇 提交于 2019-11-27 21:00:34
I've tried to compile simple hello world on Fedora 20 with Clang, and I get the following output: d.cpp:1:10: fatal error: 'iostream' file not found #include <iostream> I don't have any idea how to resolve it. user4823890 Point 3 solved the problem for me. 1. Had the same issue, fedora 21::clang 3.5.0: clang++ -std=c++14 -pedantic -Wall test_01.cpp -o test_01 -v 2. ignoring nonexistent directory "/usr/lib/gcc/i686-redhat-linux/4.9.2/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/bin/../lib/clang/3.5.0/include /usr/include End of search