If you look at the following code, I think that both the lines in main()
should call the initializer_list
constructor for InitSomething
. gcc outputs 22
as I expected, but clang just outputs a single 2
. Is clang wrong?
I am compiling with -std=c++14
.
#include <iostream>
struct InitSomething {
explicit InitSomething(int) { std::cout << '1'; }
InitSomething(std::initializer_list<int> ) { std::cout << '2'; }
operator int() { return 1; }
};
int main() {
InitSomething init_something{1};
InitSomething init_something_else{init_something};
}
The output of clang++ --version
(I am on a mac) is
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
and the output of g++ --version
on the other platform I mentioned is
g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…