llvm-capstone/clang/test/SemaCUDA/inherited-ctor.cu
Yaxun Liu a461174cfd [CUDA][HIP] Fix ShouldDeleteSpecialMember for inherited constructors
ShouldDeleteSpecialMember is called upon inherited constructors.
It calls inferCUDATargetForImplicitSpecialMember.

Normally the special member enum passed to ShouldDeleteSpecialMember
matches the constructor. However this is not true when inherited
constructor is passed, where DefaultConstructor is passed to treat
the inherited constructor as DefaultConstructor. However
inferCUDATargetForImplicitSpecialMember expects the special
member enum argument to match the constructor, which results
in assertion when this expection is not satisfied.

This patch checks whether the constructor is inherited. If true it will
get the real special member enum for the constructor and pass it
to inferCUDATargetForImplicitSpecialMember.

Differential Revision: https://reviews.llvm.org/D51809

llvm-svn: 344057
2018-10-09 15:53:14 +00:00

90 lines
1.7 KiB
Plaintext

// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
// Inherit a valid non-default ctor.
namespace NonDefaultCtorValid {
struct A {
A(const int &x) {}
};
struct B : A {
using A::A;
};
struct C {
struct B b;
C() : b(0) {}
};
void test() {
B b(0);
C c;
}
}
// Inherit an invalid non-default ctor.
// The inherited ctor is invalid because it is unable to initialize s.
namespace NonDefaultCtorInvalid {
struct S {
S() = delete;
};
struct A {
A(const int &x) {}
};
struct B : A {
using A::A;
S s;
};
struct C {
struct B b;
C() : b(0) {} // expected-error{{constructor inherited by 'B' from base class 'A' is implicitly deleted}}
// expected-note@-6{{constructor inherited by 'B' is implicitly deleted because field 's' has a deleted corresponding constructor}}
// expected-note@-15{{'S' has been explicitly marked deleted here}}
};
}
// Inherit a valid default ctor.
namespace DefaultCtorValid {
struct A {
A() {}
};
struct B : A {
using A::A;
};
struct C {
struct B b;
C() {}
};
void test() {
B b;
C c;
}
}
// Inherit an invalid default ctor.
// The inherited ctor is invalid because it is unable to initialize s.
namespace DefaultCtorInvalid {
struct S {
S() = delete;
};
struct A {
A() {}
};
struct B : A {
using A::A;
S s;
};
struct C {
struct B b;
C() {} // expected-error{{call to implicitly-deleted default constructor of 'struct B'}}
// expected-note@-6{{default constructor of 'B' is implicitly deleted because field 's' has a deleted default constructor}}
// expected-note@-15{{'S' has been explicitly marked deleted here}}
};
}