The following code outputs different results on various compilers:
- 2,1,2 on Visual Studio 2013
- 2,2,2 on Visual Studio 2015
- 2,1,1 on GCC5/c++14
- 2,2,2 on Clang 3.7 with Microsoft Codegen
- 2,1,2 on Clang 3.6/c++11 under Ubuntu 14.04
Finally, how it should work according to C++ standard?
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
class Value;
using Array = std::vector<Value>;
class Value
{
public:
Value(Array)
{
}
Value(int)
{
}
};
void foo(Array const& a)
{
printf("%d\n", (int)a.size());
}
int main()
{
Array a1 = { 1, 2 };
foo(a1);
foo(Array{ a1 });
foo(Array({ a1 }));
}
Aucun commentaire:
Enregistrer un commentaire