clang rejects derived reference argument (just fine with g++)

Viewed 60

Why does the following not compile in clang, but compiles just as expected in g++?

#include <valarray>

class Array : public std::valarray<double> {
public:
    Array(unsigned i=0) : std::valarray<double>(i) {}
};

int main() 
{
    Array a(3);
    for(int j=0; j<3; ++j) a[j]=j + 1; 

    std::valarray<double> b = std::exp(a);
}

This example was distilled to bare bones from a much more complicated situation, but the usual experiments show no issues:

After changing:

Array a(3)

to

std::valarray<double> a(3)

the code compiles just fine.

Using static_cast< std::valarray >(a) also works fine.

As requested by M.M. in the comments, the clang version is:

> clang++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix

Indeed as pointed out by "Baum mit Augen" if I add

-stdlib=libstdc++

to the compilation arguments it compiles just fine.

0 Answers
Related