C++ Primer、第 5 版で C++ を学んでいます。
C++ 11 機能を備えた単純な C++ プログラムを clang++ でコンパイルしようとしていますが、有効なコードであるはずのコンパイル エラーが発生します。
これは例です:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
int n = 0;
auto *p = &n; //<-- this compiles
cout << *p << endl;
vector<string> articles = {"a", "an", "the"}; //<-- this fails; copied from the book
return 0;
}
そして、これは完全なエラーです:
$ clang++ -std=c++11 -v test.cpp -o test
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-apple-darwin10.8.0
Thread model: posix
"/usr/local/Cellar/llvm/3.2/bin/clang" -cc1 -triple x86_64-apple-macosx10.6.0 -emit-obj -mrelax-all -disable-free -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 127.2 -v -resource-dir /usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2 -fmodule-cache-path /var/folders/pk/pkIeYbRaF-yeeUH3Q6Q5AE+++TI/-Tmp-/clang-module-cache -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/Oton/Desktop -ferror-limit 19 -fmessage-length 150 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.6.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/pk/pkIeYbRaF-yeeUH3Q6Q5AE+++TI/-Tmp-/test-w65CaF.o -x c++ test.cpp
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-apple-darwin10.8.0
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64
/usr/include/c++/4.2.1/backward
/usr/include/c++/4.0.0
/usr/include/c++/4.0.0/i686-apple-darwin8
/usr/include/c++/4.0.0/backward
/usr/local/include
/usr/local/Cellar/llvm/3.2/bin/../lib/clang/3.2/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
test.cpp:13:18: error: no matching constructor for initialization of 'vector<string>'
vector<string> articles = {"a", "an", "the"};
^ ~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.2.1/bits/stl_vector.h:255:9: note: candidate constructor [with _InputIterator = const char *] not viable: no known conversion from
'const char [4]' to 'const allocator_type' (aka 'const std::allocator<std::basic_string<char> >') for 3rd argument
vector(_InputIterator __first, _InputIterator __last,
^
/usr/include/c++/4.2.1/bits/stl_vector.h:213:7: note: candidate constructor not viable: no known conversion from 'const char [2]' to 'size_type'
(aka 'unsigned long') for 1st argument
vector(size_type __n, const value_type& __value = value_type(),
^
/usr/include/c++/4.2.1/bits/stl_vector.h:201:7: note: candidate constructor not viable: allows at most single argument '__a', but 3 arguments were
provided
vector(const allocator_type& __a = allocator_type())
^
/usr/include/c++/4.2.1/bits/stl_vector.h:231:7: note: candidate constructor not viable: requires single argument '__x', but 3 arguments were provided
vector(const vector& __x)
^
1 error generated.
私はMac、10.6.8を使用しています。オプション付きの自作でllvm/clangを構築しました:
brew install llvm -v --all-targets --rtti --shared --with-asan --with-clang --use-clang
私は何を間違っていますか?