Skip to content

clang fails on a valid code with an error: 'no matching constructor for initialization' #46701

@llvmbot

Description

@llvmbot
Bugzilla Link 47357
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@JohelEGP,@kirshamir,@zygoloid

Extended Description

Clang++ rejects the following code, while g++ accepts.

$ cat s.cpp
struct A
{
int a;
};

void f()
{
auto y = new A(1);
}

$ clang -v
clang version 11.0.0 (https://github.com/llvm/llvm-project.git ab46273)
Target: x86_64-unknown-linux-gnu
Thread model: posix

$ g++ -c -std=c++2a s.cpp
success.

$ clang++ -c std=c++2a s.cpp
s.cpp:8:16: error: no matching constructor for initialization of 'A'
auto y = new A(1);
^ ~
s.cpp:1:8: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument
struct A
^
s.cpp:1:8: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A' for 1st argument
struct A
^
s.cpp:1:8: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions