7

The code below:

struct Foo
{
    Foo(int){} // no default constructor
};

int main()
{
    Foo* pFoo = new Foo[2]{1,2}; // OK in g++, fails in clang++!
    delete[] pFoo;
}   

compiles in gcc, but fails in clang. Is the code above syntactically correct?

19
  • 3
    Just when I thought we could trust our tools. I think you broke one of them. See, this is why we can't have nice compilers. Commented May 20, 2016 at 1:23
  • 1
    The code is syntactically correct: new Foo[2] may be followed by a brace-enclosed list. I guess you are actually asking whether it is well-formed Commented May 20, 2016 at 1:57
  • 1
    Looks like clang bug to me. The error messages from clang 3.8 are nonsense, e.g. "note: in implicit initialization of array element 2 with omitted initializer" Commented May 20, 2016 at 2:08
  • 1
    If you do actually provide a default constructor, clang doesn't call it Commented May 20, 2016 at 2:08
  • 4
    See llvm.org/bugs/show_bug.cgi?id=22924 and the discussion therein; also wg21.link/cwg2102. Commented May 20, 2016 at 4:26

1 Answer 1

0

I'll turn @T.C. comment into an answer, so everyone sees what's going on without having to read through all of the comments.

This is a clang bug, the code should be accepted: http://llvm.org/bugs/show_bug.cgi?id=22924

Related: http://wg21.link/cwg2102

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.