Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.qual
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace Ints {
int zero = 0; // expected-note {{candidate found by name lookup is 'Ints::zero'}}
void f(int); // expected-note 3 {{candidate function}}
void g(int);
}
namespace Floats {
float zero = 0.0f; // expected-note {{candidate found by name lookup is 'Floats::zero'}}
void f(float); // expected-note 3 {{candidate function}}
void g(float);
}
namespace Numbers {
using namespace Ints;
using namespace Floats;
}
void test() {
int i = Ints::zero;
Ints::f(i);
float f = Floats::zero;
Floats::f(f);
double n = Numbers::zero; // expected-error {{reference to 'zero' is ambiguous}}
Numbers::f(n); // expected-error{{call to 'f' is ambiguous}}
Numbers::f(i);
Numbers::f(f);
}
namespace Numbers {
struct Number { // expected-note 2 {{candidate}}
explicit Number(double d) : d(d) {}
double d;
};
Number zero(0.0f);
void g(Number); // expected-note 2{{passing argument to parameter here}}
}
void test2() {
Numbers::Number n = Numbers::zero;
Numbers::f(n); // expected-error {{no matching function for call to 'f'}}
Numbers::g(n);
}
namespace Numbers2 {
using Numbers::f;
using Numbers::g;
}
void test3() {
Numbers::Number n = Numbers::zero;
Numbers2::f(n); // expected-error {{no matching function for call to 'f'}}
Numbers2::g(n);
int i = Ints::zero;
Numbers2::f(i);
Numbers2::g(i); // expected-error {{no viable conversion from 'int' to 'Numbers::Number'}}
float f = Floats::zero;
Numbers2::f(f);
Numbers2::g(f); // expected-error {{no viable conversion from 'float' to 'Numbers::Number'}}
}
namespace inline_ns {
int x; // expected-note 2{{found}}
inline namespace A { // expected-warning {{C++11}}
int x; // expected-note 2{{found}}
int y; // expected-note 2{{found}}
}
int y; // expected-note 2{{found}}
int k1 = x + y; // expected-error 2{{ambiguous}}
int k2 = inline_ns::x + inline_ns::y; // expected-error 2{{ambiguous}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.qual
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/namespace.qual/p5.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace A {
struct x {}; // expected-note {{candidate found by name lookup is 'A::x'}}
int x; // expected-note {{candidate found by name lookup is 'A::x'}}
struct y {}; // expected-note {{type declaration hidden}}
struct z;
void z(float);
}
namespace B {
struct x {}; // expected-note {{candidate found by name lookup is 'B::x'}}
float x; // expected-note {{candidate found by name lookup is 'B::x'}}
float y; // expected-note {{declaration hides type}}
void z(int);
}
namespace AB {
using namespace A;
using namespace B;
}
void test() {
struct AB::x foo; // expected-error {{reference to 'x' is ambiguous}}
int i = AB::x; // expected-error {{reference to 'x' is ambiguous}}
struct AB::y bar;
float f = AB::y; // expected-error {{a type named 'y' is hidden by a declaration in a different namespace}}
AB::z(i);
AB::z(f);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.qual
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct X0 {
X0 f1();
X0 f2();
};
template<typename T>
struct X1 {
X1<T>(int);
(X1<T>)(float);
X1 f2();
X1 f2(int);
X1 f2(float);
};
// Error recovery: out-of-line constructors whose names have template arguments.
template<typename T> X1<T>::X1<T>(int) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
template<typename T> (X1<T>::X1<T>)(float) { } // expected-error{{out-of-line constructor for 'X1' cannot have template arguments}}
// Error recovery: out-of-line constructor names intended to be types
X0::X0 X0::f1() { return X0(); } // expected-error{{qualified reference to 'X0' is a constructor name rather than a type wherever a constructor can be declared}}
struct X0::X0 X0::f2() { return X0(); }
template<typename T> X1<T>::X1<T> X1<T>::f2() { } // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name wherever a constructor can be declared}}
template<typename T> X1<T>::X1<T> (X1<T>::f2)(int) { } // expected-error{{qualified reference to 'X1' is a constructor name rather than a template name wherever a constructor can be declared}}
template<typename T> struct X1<T>::X1<T> (X1<T>::f2)(float) { }
// We have a special case for lookup within using-declarations that are
// member-declarations: foo::bar::baz::baz always names baz's constructor
// in such a context, even if looking up 'baz' within foo::bar::baz would
// not find the injected-class-name. Likewise foo::bar::baz<T>::baz also
// names the constructor.
namespace InhCtor {
struct A {
A(int);
protected:
int T();
};
typedef A T;
struct B : A {
// This is a using-declaration for 'int A::T()' in C++98, but is an
// inheriting constructor declaration in C++11.
using InhCtor::T::T;
};
#if __cplusplus < 201103L
B b(123); // expected-error {{no matching constructor}}
// expected-note@-7 2{{candidate constructor}}
int n = b.T(); // ok, accessible
#else
B b(123); // ok, inheriting constructor
int n = b.T(); // expected-error {{'T' is a protected member of 'InhCtor::A'}}
// expected-note@-15 {{declared protected here}}
template<typename T>
struct S : T {
struct U : S {
using S::S;
};
using T::T;
};
S<A>::U ua(0);
S<B>::U ub(0);
template<typename T>
struct X : T {
using T::Z::U::U;
};
template<typename T>
struct X2 : T {
using T::Z::template V<int>::V;
};
struct Y {
struct Z {
typedef Y U;
template<typename T> using V = Y;
};
Y(int);
};
X<Y> xy(0);
namespace Repeat {
struct A {
struct T {
T(int);
};
};
struct Z : A {
using A::A::A;
};
template<typename T>
struct ZT : T::T {
using T::T::T;
};
}
namespace NS {
struct NS {};
}
struct DerivedFromNS : NS::NS {
// No special case unless the NNS names a class.
using InhCtor::NS::NS; // expected-error {{using declaration in class refers into 'InhCtor::NS::', which is not a class}}
};
// FIXME: Consider reusing the same diagnostic between dependent and non-dependent contexts
typedef int I;
struct UsingInt {
using I::I; // expected-error {{'I' (aka 'int') is not a class, namespace, or enumeration}}
};
template<typename T> struct UsingIntTemplate {
using T::T; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
};
UsingIntTemplate<int> uit; // expected-note {{here}}
#endif
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.udir/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// When looking up a namespace-name in a using-directive or
// namespace-alias-definition, only namespace names are considered.
struct ns1 {};
void ns2();
int ns3 = 0;
namespace ns0 {
namespace ns1 {
struct test0 {};
}
namespace ns2 {
struct test1 {};
}
namespace ns3 {
struct test2 {};
}
}
using namespace ns0;
namespace test3 = ns1;
namespace test4 = ns2;
namespace test5 = ns3;
using namespace ns1;
using namespace ns2;
using namespace ns3;
test0 a;
test1 b;
test2 c;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.elab/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace test0 {
struct A {
static int foo;
};
namespace i0 {
typedef int A; // expected-note {{declared here}}
int test() {
struct A a; // expected-error {{elaborated type refers to a typedef}}
return a.foo;
}
}
namespace i1 {
template <class> class A; // expected-note {{declared here}}
int test() {
struct A a; // expected-error {{elaborated type refers to a template}}
return a.foo;
}
}
namespace i2 {
int A;
int test() {
struct A a;
return a.foo;
}
}
namespace i3 {
void A();
int test() {
struct A a;
return a.foo;
}
}
namespace i4 {
template <class T> void A();
int test() {
struct A a;
return a.foo;
}
}
// This should magically be okay; see comment in SemaDecl.cpp.
// rdar://problem/7898108
typedef struct A A;
int test() {
struct A a;
return a.foo;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.elab/templateid.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// elaborated-type-specifier:
// class-key '::'? nested-name-specifier? 'template'? simple-template-id
// Tests that this form is accepted by the compiler but does not follow
// the elaborated lookup rules of [basic.lookup.elab].
template <typename> class Ident {}; // expected-note {{previous use is here}}
namespace A {
template <typename> void Ident();
class Ident<int> AIdent; // expected-error {{refers to a function template}}
class ::Ident<int> AnotherIdent;
}
class Ident<int> GlobalIdent;
union Ident<int> GlobalIdent2; // expected-error {{ tag type that does not match }}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p7.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// PR5741
namespace test0 {
struct A {
struct B { };
struct C;
};
struct A::C : B { };
}
// Test that successive base specifiers don't screw with each other.
namespace test1 {
struct Opaque1 {};
struct Opaque2 {};
struct A {
struct B { B(Opaque1); };
};
struct B {
B(Opaque2);
};
struct C : A, B {
// Apparently the base-or-member lookup is actually ambiguous
// without this qualification.
C() : A(), test1::B(Opaque2()) {}
};
}
// Test that we don't find the injected class name when parsing base
// specifiers.
namespace test2 {
template <class T> struct bar {};
template <class T> struct foo : bar<foo> {}; // expected-error {{use of class template 'foo' requires template arguments}} expected-note {{template is declared here}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p14.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// C++0x [basic.lookup.unqual]p14:
// If a variable member of a namespace is defined outside of the
// scope of its namespace then any name used in the definition of
// the variable member (after the declarator-id) is looked up as if
// the definition of the variable member occurred in its namespace.
namespace N {
struct S {};
S i;
extern S j;
extern S j2;
}
int i = 2;
N::S N::j = i;
N::S N::j2(i);
// <rdar://problem/13317030>
namespace M {
class X { };
inline X operator-(int, X);
template<typename T>
class Y { };
typedef Y<float> YFloat;
namespace yfloat {
YFloat operator-(YFloat, YFloat);
}
using namespace yfloat;
}
using namespace M;
namespace M {
class Other {
void foo(YFloat a, YFloat b);
};
}
void Other::foo(YFloat a, YFloat b) {
YFloat c = a - b;
}
// <rdar://problem/13540899>
namespace Other {
void other_foo();
}
namespace M2 {
using namespace Other;
extern "C" {
namespace MInner {
extern "C" {
class Bar {
void bar();
};
}
}
}
}
void M2::MInner::Bar::bar() {
other_foo();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p13.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
struct S {
static const int f0 = 0;
static int f1;
};
int S::f1 = f0;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p15.cpp
|
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
class C {
public:
C(int a, int b);
};
C::C(int a, // expected-note {{previous definition}}
int b) // expected-note {{previous definition}}
try {
int c;
} catch (int a) { // expected-error {{redefinition of 'a'}}
int b; // expected-error {{redefinition of 'b'}}
++c; // expected-error {{use of undeclared identifier 'c'}}
}
void f(int i) {
struct S {
void g() try {} catch (int i) {}; // OK
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
typedef int f;
namespace N0 {
struct A {
friend void f();
void g() {
int i = f(1);
}
};
}
namespace N1 {
struct A {
friend void f(A &);
operator int();
void g(A a) {
// ADL should not apply to the lookup of 'f', it refers to the typedef
// above.
int i = f(a);
}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p12.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
struct S {};
S E0;
namespace {
enum {
E0 = 1,
E1 = E0 + 1
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.unqual/p11.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
static const int a = 10;
void f0(int a,
int b = a) { // expected-error {{default argument references parameter 'a'}}
}
template<int a,
int b = a>
class A {
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.classref/p1-cxx11.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fdiagnostics-show-option -verify %s
template<typename T>
struct set{};
struct Value {
template<typename T>
void set(T value) {}
void resolves_to_same() {
Value v;
v.set<double>(3.2);
}
};
void resolves_to_different() {
{
Value v;
// The fact that the next line is a warning rather than an error is an
// extension.
v.set<double>(3.2);
}
{
int set; // Non-template.
Value v;
v.set<double>(3.2);
}
}
namespace rdar9915664 {
struct A {
template<typename T> void a();
};
struct B : A { };
struct C : A { };
struct D : B, C {
A &getA() { return static_cast<B&>(*this); }
void test_a() {
getA().a<int>();
}
};
}
namespace PR11856 {
template<typename T> T end(T);
template <typename T>
void Foo() {
T it1;
if (it1->end < it1->end) {
}
}
template<typename T> T *end(T*);
class X { };
template <typename T>
void Foo2() {
T it1;
if (it1->end < it1->end) {
}
X *x;
if (x->end < 7) { // expected-error{{no member named 'end' in 'PR11856::X'}}
}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.classref/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// C++0x [basic.lookup.classref]p3:
// If the unqualified-id is ~type-name, the type-name is looked up in the
// context of the entire postfix-expression. If the type T of the object
// expression is of a class type C, the type-name is also looked up in the
// scope of class C. At least one of the lookups shall find a name that
// refers to (possibly cv-qualified) T.
// From core issue 305
struct A {
};
struct C {
struct A {};
void f ();
};
void C::f () {
::A *a;
a->~A ();
}
// From core issue 414
struct X {};
void f() {
X x;
struct X {};
x.~X();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.classref/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -verify %s
// C++98 [basic.lookup.classref]p1:
// In a class member access expression (5.2.5), if the . or -> token is
// immediately followed by an identifier followed by a <, the identifier must
// be looked up to determine whether the < is the beginning of a template
// argument list (14.2) or a less-than operator. The identifier is first
// looked up in the class of the object expression. If the identifier is not
// found, it is then looked up in the context of the entire postfix-expression
// and shall name a class or function template. If the lookup in the class of
// the object expression finds a template, the name is also looked up in the
// context of the entire postfix-expression and
// -- if the name is not found, the name found in the class of the object
// expression is used, otherwise
// -- if the name is found in the context of the entire postfix-expression
// and does not name a class template, the name found in the class of the
// object expression is used, otherwise
// -- if the name found is a class template, it must refer to the same
// entity as the one found in the class of the object expression,
// otherwise the program is ill-formed.
// From PR 7247
template<typename T>
struct set{}; // expected-note{{lookup from the current scope refers here}}
struct Value {
template<typename T>
void set(T value) {} // expected-note{{lookup in the object type 'Value' refers here}}
void resolves_to_same() {
Value v;
v.set<double>(3.2);
}
};
void resolves_to_different() {
{
Value v;
// The fact that the next line is a warning rather than an error is an
// extension.
v.set<double>(3.2); // expected-warning{{lookup of 'set' in member access expression is ambiguous; using member of 'Value'}}
}
{
int set; // Non-template.
Value v;
v.set<double>(3.2);
}
}
namespace rdar9915664 {
struct A {
template<typename T> void a();
};
struct B : A { };
struct C : A { };
struct D : B, C {
A &getA() { return static_cast<B&>(*this); }
void test_a() {
getA().a<int>();
}
};
}
namespace PR11856 {
template<typename T> T end(T);
template <typename T>
void Foo() {
T it1;
if (it1->end < it1->end) {
}
}
template<typename T> T *end(T*);
class X { };
template <typename T>
void Foo2() {
T it1;
if (it1->end < it1->end) {
}
X *x;
if (x->end < 7) { // expected-error{{no member named 'end' in 'PR11856::X'}}
}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.classref/p4-cxx11.cpp
|
// RUN: %clang_cc1 -std=c++11 %s -verify
// expected-no-diagnostics
struct A { void f(); };
struct C { void f(); };
struct B : A { typedef A X; };
struct D : C { typedef C X; void g(); };
void D::g()
{
B * b = new B;
b->X::f(); // lookup for X finds B::X
}
typedef int X;
void h(void)
{
B * b = new B;
b->X::f(); // lookup for X finds B::X
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-template-id.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
namespace N1 {
struct X { };
int& f(void*);
}
namespace N2 {
template<typename T> struct Y { };
}
namespace N3 {
void test() {
int &ir = f((N2::Y<N1::X>*)0);
}
}
int g(void *);
long g(N1::X);
namespace N1 {
void h(int (*)(void *));
}
void test() {
h((&g));
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace A {
class A {
friend void func(A);
friend A operator+(A,A);
};
}
namespace B {
class B {
static void func(B);
};
B operator+(B,B);
}
namespace D {
class D {};
}
namespace C {
class C {}; // expected-note {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'B::B' to 'const C::C &' for 1st argument}}
void func(C); // expected-note {{'C::func' declared here}} \
// expected-note {{passing argument to parameter here}}
C operator+(C,C);
D::D operator+(D::D,D::D);
}
namespace D {
using namespace C;
}
namespace Test {
void test() {
func(A::A());
// FIXME: namespace-aware typo correction causes an extra, misleading
// message in this case; some form of backtracking, diagnostic message
// delaying, or argument checking before emitting diagnostics is needed to
// avoid accepting and printing out a typo correction that proves to be
// incorrect once argument-dependent lookup resolution has occurred.
func(B::B()); // expected-error {{use of undeclared identifier 'func'; did you mean 'C::func'?}} \
// expected-error {{no viable conversion from 'B::B' to 'C::C'}}
func(C::C());
A::A() + A::A();
B::B() + B::B();
C::C() + C::C();
D::D() + D::D(); // expected-error {{invalid operands to binary expression ('D::D' and 'D::D')}}
}
}
// PR6716
namespace test1 {
template <class T> class A {
template <class U> friend void foo(A &, U); // expected-note {{not viable: 1st argument ('const A<int>') would lose const qualifier}}
public:
A();
};
void test() {
const A<int> a;
foo(a, 10); // expected-error {{no matching function for call to 'foo'}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// FIXME: embellish
namespace test0 {
namespace A {
class Foo {
};
void foo(const Foo &foo);
}
class Test {
enum E { foo = 0 };
void test() {
foo(A::Foo()); // expected-error {{not a function}}
}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace N {
struct X { };
X operator+(X, X);
void f(X); // expected-note 2 {{'N::f' declared here}}
void g(X); // expected-note{{candidate function}}
void test_multiadd(X x) {
(void)(x + x);
}
}
namespace M {
struct Y : N::X { };
}
void f();
void test_operator_adl(N::X x, M::Y y) {
(void)(x + x);
(void)(y + y);
}
void test_func_adl(N::X x, M::Y y) {
f(x);
f(y);
(f)(x); // expected-error{{too many arguments to function call, expected 0, have 1; did you mean 'N::f'?}}
::f(x); // expected-error{{too many arguments to function call, expected 0, have 1; did you mean 'N::f'?}}
}
namespace N {
void test_multiadd2(X x) {
(void)(x + x);
}
}
void test_func_adl_only(N::X x) {
g(x);
}
namespace M {
int g(N::X); // expected-note{{candidate function}}
void test(N::X x) {
g(x); // expected-error{{call to 'g' is ambiguous}}
int i = (g)(x);
int g(N::X);
g(x); // okay; calls locally-declared function, no ADL
}
}
void test_operator_name_adl(N::X x) {
(void)operator+(x, x);
}
struct Z { };
int& f(Z);
namespace O {
char &f();
void test_global_scope_adl(Z z) {
{
int& ir = f(z);
}
}
}
extern "C" {
struct L { int x; };
}
void h(L); // expected-note{{candidate function}}
namespace P {
void h(L); // expected-note{{candidate function}}
void test_transparent_context_adl(L l) {
{
h(l); // expected-error {{call to 'h' is ambiguous}}
}
}
}
namespace test5 {
namespace NS {
struct A;
void foo(void (*)(A&));
}
void bar(NS::A& a);
void test() {
foo(&bar);
}
}
// PR6762: __builtin_va_list should be invisible to ADL on all platforms.
void test6_function(__builtin_va_list &argv);
namespace test6 {
void test6_function(__builtin_va_list &argv);
void test() {
__builtin_va_list args;
test6_function(args);
}
}
// PR13682: we might need to instantiate class temploids.
namespace test7 {
namespace inner {
class A {};
void test7_function(A &);
}
template <class T> class B : public inner::A {};
void test(B<int> &ref) {
test7_function(ref);
}
}
// Like test7, but ensure we don't complain if the type is properly
// incomplete.
namespace test8 {
template <class T> class B;
void test8_function(B<int> &);
void test(B<int> &ref) {
test8_function(ref);
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.def.odr/p2-typeid.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// C++ [basic.def.odr]p2:
// An expression is potentially evaluated unless it [...] is the
// operand of the typeid operator and the expression does not
// designate an lvalue of polymorphic class type.
// FIXME: This should really include <typeinfo>, but we don't have that yet.
namespace std {
class type_info;
}
struct Poly {
virtual ~Poly();
};
struct NonPoly { };
template<typename T, typename Result = T>
struct X {
Result f(T t) { return t + t; } // expected-error{{invalid operands}}
void g(T t) {
(void)typeid(f(t)); // expected-note{{here}}
}
};
void test(X<Poly> xp, X<Poly, Poly&> xpr, X<NonPoly> xnp, X<NonPoly, NonPoly&> xnpr) {
// These are okay (although GCC and EDG get them wrong).
xp.g(Poly());
xnp.g(NonPoly());
xnpr.g(NonPoly());
// Triggers an error (as it should);
xpr.g(Poly()); // expected-note{{instantiation of member function}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.def.odr/p1-var.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// C++ [basic.def.odr]p1:
// No translation unit shall contain more than one definition of any
// variable, [...].
// Bad: in C++, these are both definitions. None of that C99 tentative stuff.
int i; // expected-note {{previous}}
int i; // expected-error {{redefinition}}
// OK: decl + def
extern int j;
int j;
// OK: def + decl
int k;
extern int k;
// Bad. The important thing here is that we don't emit the diagnostic twice.
int l = 1; // expected-note {{previous}}
int l = 2; // expected-error {{redefinition}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic/p2-noexceptions.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
namespace std {
class bad_alloc { };
typedef __SIZE_TYPE__ size_t;
}
class foo { virtual ~foo(); };
void* operator new(std::size_t);
void* operator new[](std::size_t);
void operator delete(void*);
void operator delete[](void*);
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic/p2-nodef.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
int *use_new(int N) {
return new int [N];
}
int std = 17;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fexceptions -fcxx-exceptions -verify %s
int *use_new(int N) {
if (N == 1)
return new int;
return new int [N];
}
void use_delete(int* ip, int N) {
if (N == 1)
delete ip;
else
delete [] ip;
}
namespace std {
class bad_alloc { };
typedef __SIZE_TYPE__ size_t;
}
void* operator new(std::size_t) throw(std::bad_alloc); // expected-note{{previous declaration}}
void* operator new[](std::size_t) throw(std::bad_alloc);
void operator delete(void*) throw(); // expected-note{{previous declaration}}
void operator delete[](void*) throw();
void* operator new(std::size_t); // expected-warning{{'operator new' is missing exception specification 'throw(std::bad_alloc)'}}
void operator delete(void*); // expected-warning{{'operator delete' is missing exception specification 'throw()'}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic/basic.stc.dynamic.deallocation/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct A {
void operator delete(void*);
};
namespace NS {
void operator delete(void *); // expected-error {{'operator delete' cannot be declared inside a namespace}}
}
static void operator delete(void *); // expected-error {{follows non-static declaration}} expected-note {{implicit}}
static void operator delete(void *, int, int); // expected-error {{'operator delete' cannot be declared static in global scope}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.stc/basic.stc.dynamic/basic.stc.dynamic.allocation/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
#include <stddef.h>
struct A {
void *operator new(size_t);
};
namespace NS {
void *operator new(size_t);; // expected-error {{'operator new' cannot be declared inside a namespace}}
}
static void *operator new(size_t); // expected-error {{static declaration of 'operator new' follows non-static declaration}} expected-note {{previous}}
static void *operator new(size_t, int, int); // expected-error {{'operator new' cannot be declared static in global scope}}
struct B {
void operator new(size_t); // expected-error {{'operator new' must return type 'void *'}}
};
struct C {
void *operator new(); // expected-error {{'operator new' must have at least one parameter}}
};
struct D {
void *operator new(bool); // expected-error {{'operator new' takes type size_t}}
};
struct E {
void *operator new(size_t = 0); // expected-error {{parameter of 'operator new' cannot have a default argument}}
};
struct F {
template<typename T> void *operator new(size_t, int);
};
struct G {
template<typename T> T operator new(size_t, int); // expected-error {{'operator new' cannot have a dependent return type; use 'void *' instead}}
};
struct H {
template<typename T> void *operator new(T, int); // expected-error {{'operator new' cannot take a dependent type as first parameter; use size_t}}
};
struct I {
template<typename T> void *operator new(size_t); // expected-error {{'operator new' template must have at least two parameters}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.start
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.start/basic.start.main/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST1
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST2
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST3
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST4
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST5
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST6
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST7
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST8
// RUN: cp %s %t
// RUN: %clang_cc1 -x c++ %s -std=c++11 -fsyntax-only -verify -DTEST9
// RUN: not %clang_cc1 -x c++ %t -std=c++11 -fixit -DTEST9
// RUN: %clang_cc1 -x c++ %t -std=c++11 -fsyntax-only -DTEST9
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST10
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST11
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST12
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST13
// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST14
#if TEST1
// expected-no-diagnostics
typedef int Int;
typedef char Char;
typedef Char* Carp;
Int main(Int argc, Carp argv[]) {
}
#elif TEST2
// expected-no-diagnostics
typedef int Int;
typedef char Char;
typedef Char* Carp;
Int main(Int argc, Carp argv[], Char *env[]) {
}
#elif TEST3
// expected-no-diagnostics
int main() {
}
#elif TEST4
static int main() { // expected-error {{'main' is not allowed to be declared static}}
}
#elif TEST5
inline int main() { // expected-error {{'main' is not allowed to be declared inline}}
}
#elif TEST6
void // expected-error {{'main' must return 'int'}}
main( // expected-error {{first parameter of 'main' (argument count) must be of type 'int'}}
float a
) {
}
const int main(); // expected-error {{'main' must return 'int'}}
#elif TEST7
// expected-no-diagnostics
int main(int argc, const char* const* argv) {
}
#elif TEST8
template<typename T>
int main() { } // expected-error{{'main' cannot be a template}}
#elif TEST9
constexpr int main() { } // expected-error{{'main' is not allowed to be declared constexpr}}
#elif TEST10
// PR15100
// expected-no-diagnostics
typedef char charT;
int main(int, const charT**) {}
#elif TEST11
// expected-no-diagnostics
typedef char charT;
int main(int, charT* const *) {}
#elif TEST12
// expected-no-diagnostics
typedef char charT;
int main(int, const charT* const *) {}
#elif TEST13
int main(void) {}
template <typename T>
int main(void); // expected-error{{'main' cannot be a template}}
#elif TEST14
template <typename T>
int main(void); // expected-error{{'main' cannot be a template}}
int main(void) {}
#else
#error Unknown test mode
#endif
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.start
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.start/basic.start.init/p3.cpp
|
// RUN: %clang_cc1 -verify %s -pedantic-errors
// RUN: %clang_cc1 -verify %s -pedantic-errors -DINLINE
// RUN: %clang_cc1 -verify %s -pedantic-errors -DSTATIC
// RUN: %clang_cc1 -verify %s -pedantic-errors -std=c++11 -DCONSTEXPR
// RUN: %clang_cc1 -verify %s -std=c++11 -DDELETED
#if INLINE
inline // expected-error {{'main' is not allowed to be declared inline}}
#elif STATIC
static // expected-error {{'main' is not allowed to be declared static}}
#elif CONSTEXPR
constexpr // expected-error {{'main' is not allowed to be declared constexpr}}
#endif
int main(int argc, char **argv)
#if DELETED
= delete; // expected-error {{'main' is not allowed to be deleted}}
#else
{
int (*pmain)(int, char**) = &main; // expected-error {{ISO C++ does not allow 'main' to be used by a program}}
if (argc)
main(0, 0); // expected-error {{ISO C++ does not allow 'main' to be used by a program}}
}
#endif
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.link/p7.cpp
|
// RUN: %clang_cc1 -verify -std=c++1y %s
// Example from the standard.
namespace X {
void p() {
q(); // expected-error {{undeclared}}
extern void q();
}
void middle() {
q(); // expected-error {{undeclared}}
}
void q() { /*...*/ }
void bottom() {
q();
}
}
int q();
namespace Test1 {
void f() {
extern int a; // expected-note {{previous}}
int g(void); // expected-note {{previous}}
}
double a; // expected-error {{different type: 'double' vs 'int'}}
double g(); // expected-error {{differ only in their return type}}
}
namespace Test2 {
void f() {
extern int a; // expected-note {{previous}}
int g(void); // expected-note {{previous}}
}
void h() {
extern double a; // expected-error {{different type: 'double' vs 'int'}}
double g(void); // expected-error {{differ only in their return type}}
}
}
namespace Test3 {
constexpr void (*f())() {
void h();
return &h;
}
constexpr void (*g())() {
void h();
return &h;
}
static_assert(f() == g(), "");
}
namespace Test4 {
template<typename T>
constexpr void (*f())() {
void h();
return &h;
}
static_assert(f<int>() == f<char>(), "");
void h();
static_assert(f<int>() == &h, "");
}
namespace Test5 {
constexpr auto f() -> void (*)() {
void g();
struct X {
friend void g();
static constexpr auto h() -> void (*)() { return g; }
};
return X::h();
}
void g();
static_assert(f() == g, "");
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.link/p9.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// FIXME: This test is woefully incomplete.
namespace N { } // expected-note{{here}}
// First bullet: two names with external linkage that refer to
// different kinds of entities.
void f() {
int N(); // expected-error{{redefinition}} expected-warning{{interpreted as a function declaration}} expected-note {{replace parentheses with an initializer}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.link/p6.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s
// expected-no-diagnostics
// C++11 [basic.link]p6:
// The name of a function declared in block scope and the name
// of a variable declared by a block scope extern declaration
// have linkage. If there is a visible declaration of an entity
// with linkage having the same name and type, ignoring entities
// declared outside the innermost enclosing namespace scope, the
// block scope declaration declares that same entity and
// receives the linkage of the previous declaration.
extern int same_entity;
constexpr int *get1() {
int same_entity = 0; // not the same entity
{
extern int same_entity;
return &same_entity;
}
}
static_assert(get1() == &same_entity, "failed to find previous decl");
static int same_entity_2[3];
constexpr int *get2() {
// This is a redeclaration of the same entity, even though it doesn't
// inherit the type of the prior declaration.
extern int same_entity_2[];
return same_entity_2;
}
static_assert(get2() == same_entity_2, "failed to find previous decl");
static int different_entities;
constexpr int *get3() {
int different_entities = 0;
{
// FIXME: This is not a redeclaration of the prior entity, because
// it is not visible here. Under DR426, this is ill-formed, and without
// it, the static_assert below should fail.
extern int different_entities;
return &different_entities;
}
}
static_assert(get3() == &different_entities, "failed to find previous decl");
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope/basic.scope.hiding/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// rdar4641403
namespace N {
struct X { // expected-note{{candidate found by name lookup}}
float b;
};
}
using namespace N;
typedef struct {
int a;
} X; // expected-note{{candidate found by name lookup}}
struct Y { };
void Y(int) { }
void f() {
X *x; // expected-error{{reference to 'X' is ambiguous}}
Y(1); // okay
}
namespace PR17731 {
void f() {
struct S { S() {} };
int S(void);
int a = S();
struct S b;
{
int S(void);
int a = S();
struct S c = b;
}
{
struct S { S() {} }; // expected-note {{candidate}}
int a = S(); // expected-error {{no viable conversion from 'S'}}
struct S c = b; // expected-error {{no viable conversion from 'struct S'}}
}
}
void g() {
int S(void);
struct S { S() {} };
int a = S();
struct S b;
{
int S(void);
int a = S();
struct S c = b;
}
{
struct S { S() {} }; // expected-note {{candidate}}
int a = S(); // expected-error {{no viable conversion from 'S'}}
struct S c = b; // expected-error {{no viable conversion from 'struct S'}}
}
}
struct A {
struct B;
void f();
int B;
};
struct A::B {};
void A::f() {
B = 123;
struct B b;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope/basic.scope.local/p4-0x.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
void f() {
int b;
int arr[] = {1, 2, 3};
if (bool b = true) // expected-note 2{{previous definition}}
bool b; // expected-error {{redefinition}}
else
int b; // expected-error {{redefinition}}
while (bool b = true) // expected-note {{previous definition}}
int b; // expected-error {{redefinition}}
for (int c; // expected-note 2{{previous definition}}
bool c = true;) // expected-error {{redefinition}}
double c; // expected-error {{redefinition}}
switch (int n = 37 + 5) // expected-note {{previous definition}}
int n; // expected-error {{redefinition}}
for (int a : arr) // expected-note {{previous definition}}
int a = 0; // expected-error {{redefinition}}
if (bool b = true) { // expected-note 2{{previous definition}}
int b; // expected-error {{redefinition}}
} else {
int b; // expected-error {{redefinition}}
}
while (bool b = true) { // expected-note {{previous definition}}
int b; // expected-error {{redefinition}}
}
for (int c; // expected-note 2{{previous definition}}
bool c = true;) { // expected-error {{redefinition}}
double c; // expected-error {{redefinition}}
}
switch (int n = 37 + 5) { // expected-note {{previous definition}}
int n; // expected-error {{redefinition}}
}
for (int &a : arr) { // expected-note {{previous definition}}
int a = 0; // expected-error {{redefinition}}
}
if (bool b = true) {{ // expected-note {{previous definition}}
bool b;
}} else {
int b; // expected-error {{redefinition}}
}
if (bool b = true) { // expected-note {{previous definition}}
bool b; // expected-error {{redefinition}}
} else {{
int b;
}}
if (bool b = true) {{
bool b;
}} else {{
int b;
}}
while (bool b = true) {{
int b;
}}
for (int c; // expected-note {{previous definition}}
bool c = true; ) {{ // expected-error {{redefinition}}
double c;
}}
switch (int n = 37 + 5) {{
int n;
}}
for (int &a : arr) {{
int a = 0;
}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope/basic.scope.local/p2.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -fexceptions -verify %s
void func1(int i) { // expected-note{{previous definition is here}}
int i; // expected-error{{redefinition of 'i'}}
}
void func2(int i) try { // expected-note{{previous definition is here}}
int i; // expected-error{{redefinition of 'i'}}
} catch (...) {
}
void func3(int i) try { // expected-note {{previous definition is here}}
} catch (int i) { // expected-error {{redefinition of 'i'}}
}
void func4(int i) try { // expected-note{{previous definition is here}}
} catch (...) {
int i; // expected-error{{redefinition of 'i'}}
}
void func5() try {
int i;
} catch (...) {
int j = i; // expected-error{{use of undeclared identifier 'i'}}
}
void func6() try {
} catch (int i) { // expected-note{{previous definition is here}}
int i; // expected-error{{redefinition of 'i'}}
}
void func7() {
try {
} catch (int i) { // expected-note{{previous definition is here}}
int i; // expected-error{{redefinition of 'i'}}
}
}
void func8() {
int i;
try {
int i;
} catch (...) {
}
}
void func9() {
if (bool b = true)
try {
int b; // FIXME: this probably should be invalid, maybe
} catch (...) {
}
}
void func10() {
if (bool b = true)
if (true) {
int b; // FIXME: decide whether this is valid
}
}
void func11(int a) {
try {
} catch (int a) { // OK
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope/basic.scope.pdecl/p9.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// Template type parameters.
typedef unsigned char T;
template<typename T = T> struct X0 { };
template<> struct X0<unsigned char> { static const bool value = true; };
int array0[X0<>::value? 1 : -1];
// Non-type template parameters.
const int N = 17;
template<int N = N> struct X1 { };
template<> struct X1<17> { static const bool value = true; };
int array1[X1<>::value? 1 : -1];
// Template template parameters.
template<template<class> class X0 = X0> struct X2 { };
template<> struct X2<X0> { static const bool value = true; };
int array2[X2<>::value? 1 : -1];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.scope/basic.scope.pdecl/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// Classes.
namespace Class {
namespace NS {
class C {}; // expected-note {{candidate}}
}
using namespace NS;
class C : C {}; // expected-error {{reference to 'C' is ambiguous}} \
expected-note {{candidate}}
}
// Enumerations.
enum E {
EPtrSize = sizeof((E*)0) // ok, E is already declared
};
// Alias declarations. clang implements the proposed resolution to N1044.
namespace Alias {
namespace NS {
class C;
}
using namespace NS;
using C = C; // ok, C = B::C
using C = NS::C; // ok, same type
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/basic/basic.types/p10.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s -DCXX1Y
struct NonLiteral { NonLiteral(); };
// A type is a literal type if it is:
// [C++1y] - void
constexpr void f() {}
#ifndef CXX1Y
// expected-error@-2 {{'void' is not a literal type}}
#endif
// - a scalar type
constexpr int f1(double) { return 0; }
// - a reference type
struct S { S(); };
constexpr int f2(S &) { return 0; }
struct BeingDefined;
extern BeingDefined beingdefined;
struct BeingDefined {
static constexpr BeingDefined& t = beingdefined;
};
// - a class type that has all of the following properties:
// (implied) - it is complete
struct Incomplete; // expected-note 2{{forward declaration of 'Incomplete'}}
template<class T> struct ClassTemp {};
constexpr Incomplete incomplete = {}; // expected-error {{constexpr variable cannot have non-literal type 'const Incomplete'}} expected-note {{incomplete type 'const Incomplete' is not a literal type}}
constexpr Incomplete incomplete2[] = {}; // expected-error {{constexpr variable cannot have non-literal type 'Incomplete const[]'}} expected-note {{incomplete type 'Incomplete const[]' is not a literal type}}
constexpr ClassTemp<int> classtemplate = {};
constexpr ClassTemp<int> classtemplate2[] = {};
// - it has a trivial destructor
struct UserProvDtor {
~UserProvDtor(); // expected-note {{has a user-provided destructor}}
};
constexpr int f(UserProvDtor) { return 0; } // expected-error {{'UserProvDtor' is not a literal type}}
struct NonTrivDtor {
constexpr NonTrivDtor();
virtual ~NonTrivDtor() = default; // expected-note {{has a non-trivial destructor}} expected-note {{because it is virtual}}
};
constexpr int f(NonTrivDtor) { return 0; } // expected-error {{'NonTrivDtor' is not a literal type}}
struct NonTrivDtorBase {
~NonTrivDtorBase();
};
template<typename T>
struct DerivedFromNonTrivDtor : T { // expected-note {{'DerivedFromNonTrivDtor<NonTrivDtorBase>' is not literal because it has base class 'NonTrivDtorBase' of non-literal type}}
constexpr DerivedFromNonTrivDtor();
};
constexpr int f(DerivedFromNonTrivDtor<NonTrivDtorBase>) { return 0; } // expected-error {{constexpr function's 1st parameter type 'DerivedFromNonTrivDtor<NonTrivDtorBase>' is not a literal type}}
struct TrivDtor {
constexpr TrivDtor();
};
constexpr int f(TrivDtor) { return 0; }
struct TrivDefaultedDtor {
constexpr TrivDefaultedDtor();
~TrivDefaultedDtor() = default;
};
constexpr int f(TrivDefaultedDtor) { return 0; }
// - it is an aggregate type or has at least one constexpr constructor or
// constexpr constructor template that is not a copy or move constructor
struct Agg {
int a;
char *b;
};
constexpr int f3(Agg a) { return a.a; }
struct CtorTemplate {
template<typename T> constexpr CtorTemplate(T);
};
struct CopyCtorOnly { // expected-note {{'CopyCtorOnly' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors}}
constexpr CopyCtorOnly(CopyCtorOnly&);
};
constexpr int f(CopyCtorOnly) { return 0; } // expected-error {{'CopyCtorOnly' is not a literal type}}
struct MoveCtorOnly { // expected-note {{no constexpr constructors other than copy or move constructors}}
constexpr MoveCtorOnly(MoveCtorOnly&&);
};
constexpr int f(MoveCtorOnly) { return 0; } // expected-error {{'MoveCtorOnly' is not a literal type}}
template<typename T>
struct CtorArg {
constexpr CtorArg(T);
};
constexpr int f(CtorArg<int>) { return 0; } // ok
constexpr int f(CtorArg<NonLiteral>) { return 0; } // ok, ctor is still constexpr
// We have a special-case diagnostic for classes with virtual base classes.
struct VBase {};
struct HasVBase : virtual VBase {}; // expected-note 2{{virtual base class declared here}}
struct Derived : HasVBase {
constexpr Derived() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}}
};
template<typename T> struct DerivedFromVBase : T { // expected-note {{struct with virtual base class is not a literal type}}
constexpr DerivedFromVBase();
};
constexpr int f(DerivedFromVBase<HasVBase>) {} // expected-error {{constexpr function's 1st parameter type 'DerivedFromVBase<HasVBase>' is not a literal type}}
template<typename T> constexpr DerivedFromVBase<T>::DerivedFromVBase() : T() {}
constexpr int nVBase = (DerivedFromVBase<HasVBase>(), 0); // expected-error {{constant expression}} expected-note {{cannot construct object of type 'DerivedFromVBase<HasVBase>' with virtual base class in a constant expression}}
// - it has all non-static data members and base classes of literal types
struct NonLitMember {
S s; // expected-note {{has data member 's' of non-literal type 'S'}}
};
constexpr int f(NonLitMember) {} // expected-error {{1st parameter type 'NonLitMember' is not a literal type}}
struct NonLitBase :
S { // expected-note {{base class 'S' of non-literal type}}
constexpr NonLitBase();
};
constexpr int f(NonLitBase) { return 0; } // expected-error {{'NonLitBase' is not a literal type}}
struct LitMemBase : Agg {
Agg agg;
};
template<typename T>
struct MemberType {
T t; // expected-note {{'MemberType<NonLiteral>' is not literal because it has data member 't' of non-literal type 'NonLiteral'}}
constexpr MemberType();
};
constexpr int f(MemberType<int>) { return 0; }
constexpr int f(MemberType<NonLiteral>) { return 0; } // expected-error {{not a literal type}}
// - an array of literal type [C++1y] other than an array of runtime bound
struct ArrGood {
Agg agg[24];
double d[12];
TrivDtor td[3];
TrivDefaultedDtor tdd[3];
};
constexpr int f(ArrGood) { return 0; }
struct ArrBad {
S s[3]; // expected-note {{data member 's' of non-literal type 'S [3]'}}
};
constexpr int f(ArrBad) { return 0; } // expected-error {{1st parameter type 'ArrBad' is not a literal type}}
constexpr int arb(int n) {
int a[n]; // expected-error {{variable of non-literal type 'int [n]' cannot be defined in a constexpr function}}
}
constexpr long Overflow[ // expected-error {{constexpr variable cannot have non-literal type 'long const[(1 << 30) << 2]'}}
(1 << 30) << 2]{}; // expected-warning {{requires 34 bits to represent}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/p4-0x.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
// expected-no-diagnostics
struct X {
void f() &;
void g() &&;
};
void (X::*pmf)() & = &X::f;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.name/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
namespace pr6200 {
struct v {};
enum E { e };
struct s {
int i;
operator struct v() { return v(); };
operator enum E() { return e; }
};
void f()
{
// None of these is a declaration.
(void)new struct s;
(void)new enum E;
(void)&s::operator struct v;
(void)&s::operator enum E;
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/p7.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s
struct NotAggregateBase {};
struct A : NotAggregateBase {
private:
A() = default; // expected-note {{here}}
};
A a = {}; // expected-error {{calling a private constructor}}
struct B : NotAggregateBase {
explicit B() = default; // expected-note {{here}}
};
B b = {}; // expected-error {{chosen constructor is explicit}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/p14-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct NoDefault {
NoDefault() = delete; // expected-note {{here}}
NoDefault(int);
};
struct Explicit { // expected-note 2 {{candidate}} expected-note {{here}}
explicit Explicit(int);
};
struct NoCopy {
NoCopy();
NoCopy(const NoCopy &) = delete; // expected-note {{here}}
};
struct NoMove {
NoMove();
NoMove(NoMove &&) = delete; // expected-note {{here}}
};
class Private {
Private(int); // expected-note {{here}}
public:
Private();
};
class Friend {
friend class S;
Friend(int);
};
class S {
NoDefault nd1;
NoDefault nd2 = 42;
Explicit e1; // expected-note {{here}}
Explicit e2 = 42; // expected-error {{no viable conversion}}
NoCopy nc = NoCopy(); // expected-error {{call to deleted}}
NoMove nm = NoMove(); // expected-error {{call to deleted}}
Private p = 42; // expected-error {{private constructor}}
Friend f = 42;
S() {} // expected-error {{call to deleted constructor of 'NoDefault'}} \
expected-error {{must explicitly initialize the member 'e1' which does not have a default constructor}}
S(int) : nd1(42), e1(42) {}
};
// FIXME: test the other forms which use copy-initialization
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/p5.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// A program that calls for default-initialization or value-initialization of
// an entity of reference type is illformed. If T is a cv-qualified type, the
// cv-unqualified version of T is used for these definitions of
// zero-initialization, default-initialization, and value-initialization.
struct S { // expected-error {{implicit default constructor for 'S' must explicitly initialize the reference member}}
int &x; // expected-note {{declared here}} expected-error 3{{reference to type 'int' requires an initializer}}
};
S s; // expected-note {{implicit default constructor for 'S' first required here}}
S f() {
return S(); // expected-note {{in value-initialization of type 'S' here}}
}
struct T
: S { // expected-note 2{{in value-initialization of type 'S' here}}
};
T t = T(); // expected-note {{in value-initialization of type 'T' here}}
struct U {
T t[3]; // expected-note {{in value-initialization of type 'T' here}}
};
U u = U(); // expected-note {{in value-initialization of type 'U' here}}
// Ensure that we handle C++11 in-class initializers properly as an extension.
// In this case, there is no user-declared default constructor, so we
// recursively apply the value-initialization checks, but we will emit a
// constructor call anyway, because the default constructor is not trivial.
struct V {
int n;
int &r = n; // expected-warning {{C++11}}
};
V v = V(); // ok
struct W {
int n;
S s = { n }; // expected-warning {{C++11}}
};
W w = W(); // ok
// Ensure we're not faking this up by making the default constructor
// non-trivial.
#define static_assert(B, S) typedef int assert_failed[(B) ? 1 : -1];
static_assert(__has_trivial_constructor(S), "");
static_assert(__has_trivial_constructor(T), "");
static_assert(__has_trivial_constructor(U), "");
static_assert(!__has_trivial_constructor(V), "");
static_assert(!__has_trivial_constructor(W), "");
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/p6.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// FIXME: Very incomplete!
// If a program calls for the default initialization of an object of a
// const-qualified type T, T shall be a class type with a
// user-provided default constructor.
struct MakeNonPOD { MakeNonPOD(); };
struct NoUserDefault : public MakeNonPOD { };
struct HasUserDefault { HasUserDefault(); };
void test_const_default_init() {
const NoUserDefault x1; // expected-error{{default initialization of an object of const type 'const NoUserDefault' without a user-provided default constructor}}
const HasUserDefault x2;
const int x3; // expected-error{{default initialization of an object of const type 'const int'}}
}
// rdar://8501008
struct s0 {};
struct s1 { static const s0 foo; };
const struct s0 s1::foo; // expected-error{{default initialization of an object of const type 'const struct s0' without a user-provided default constructor}}
template<typename T>
struct s2 {
static const s0 foo;
};
template<> const struct s0 s2<int>::foo; // okay
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p7.cpp
|
// RUN: %clang_cc1 -Wno-uninitialized -std=c++1y %s -verify
// expected-no-diagnostics
struct S { int a; const char *b; int c; int d = b[a]; };
constexpr S ss = { 1, "asdf" };
static_assert(ss.a == 1, "");
static_assert(ss.b[2] == 'd', "");
static_assert(ss.c == 0, "");
static_assert(ss.d == 's', "");
struct X { int i, j, k = 42; };
constexpr X a[] = { 1, 2, 3, 4, 5, 6 };
constexpr X b[2] = { { 1, 2, 3 }, { 4, 5, 6 } };
constexpr bool operator==(X a, X b) {
return a.i == b.i && a.j == b.j && a.k == b.k;
}
static_assert(sizeof(a) == sizeof(b), "");
static_assert(a[0] == b[0], "");
static_assert(a[1] == b[1], "");
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p4.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 -pedantic -Werror %s
int a1[] = { 1, 3, 5 };
void f() {
int a2[] = { 1, 3, 5 };
}
template <typename T>
void tf() {
T t;
// Element type may be dependent
T a3[] = { 1, 3, 5 };
// As might be the initializer list, value
int a5[] = { sizeof(T) };
// or even type.
int a6[] = { t.get() };
}
// Allowed by GNU extension
int a4[] = {}; // expected-error {{zero size arrays}}
struct Incomplete; // expected-note {{forward declaration of 'Incomplete'}}
struct A {
Incomplete i; // expected-error {{field has incomplete type 'Incomplete'}}
};
A a[] = { 0 }; // PR13971: don't hang.
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.aggr/p1-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s -DCXX1Y
// An aggregate is an array or a class...
struct Aggr {
private:
static const int n;
void f();
protected:
struct Inner { int m; };
public:
bool &br; // expected-note {{default constructor of 'Aggr' is implicitly deleted because field 'br' of reference type 'bool &' would not be initialized}}
};
bool b;
Aggr ag = { b };
// with no user-provided constructors, ...
struct NonAggr1a { // expected-note 2 {{candidate constructor}}
NonAggr1a(int, int); // expected-note {{candidate constructor}}
int k;
};
NonAggr1a na1a = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr1a'}}
struct NonAggr1b {
NonAggr1b(const NonAggr1b &); // expected-note {{candidate constructor}}
int k;
};
NonAggr1b na1b = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr1b'}}
// no brace-or-equal-initializers for non-static data members, ...
// Note, this bullet was removed in C++1y.
struct NonAggr2 {
int m = { 123 };
};
NonAggr2 na2 = { 42 };
#ifndef CXX1Y
// expected-error@-2 {{no matching constructor for initialization of 'NonAggr2'}}
// expected-note@-6 3 {{candidate constructor}}
#endif
// no private...
struct NonAggr3 { // expected-note 3 {{candidate constructor}}
private:
int n;
};
NonAggr3 na3 = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr3'}}
// or protected non-static data members, ...
struct NonAggr4 { // expected-note 3 {{candidate constructor}}
protected:
int n;
};
NonAggr4 na4 = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr4'}}
// no base classes, ...
struct NonAggr5 : Aggr { // expected-note 3 {{candidate constructor}}
};
NonAggr5 na5 = { b }; // expected-error {{no matching constructor for initialization of 'NonAggr5'}}
template<typename...BaseList>
struct MaybeAggr5a : BaseList... {}; // expected-note {{default constructor of 'MaybeAggr5a<Aggr>' is implicitly deleted because base class 'Aggr' has a deleted default constructor}}
MaybeAggr5a<> ma5a0 = {}; // ok
MaybeAggr5a<Aggr> ma5a1 = {}; // expected-error {{call to implicitly-deleted default constructor of 'MaybeAggr5a<Aggr>'}}
// and no virtual functions.
struct NonAggr6 { // expected-note 3 {{candidate constructor}}
virtual void f();
int n;
};
NonAggr6 na6 = { 42 }; // expected-error {{no matching constructor for initialization of 'NonAggr6'}}
struct DefaultedAggr {
int n;
DefaultedAggr() = default;
DefaultedAggr(const DefaultedAggr &) = default;
DefaultedAggr(DefaultedAggr &&) = default;
DefaultedAggr &operator=(const DefaultedAggr &) = default;
DefaultedAggr &operator=(DefaultedAggr &&) = default;
~DefaultedAggr() = default;
};
DefaultedAggr da = { 42 } ;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/basic.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
void f0() {
int &ir = { 17 }; // expected-error{{reference to type 'int' cannot bind to an initializer list}}
}
namespace PR12453 {
template<typename T>
void f(int i) {
T x{i}; // expected-error{{non-constant-expression cannot be narrowed from type 'int' to 'float' in initializer list}} \
// expected-note{{insert an explicit cast to silence this issue}}
T y{i}; // expected-error{{non-constant-expression cannot be narrowed from type 'int' to 'float' in initializer list}} \
// expected-note{{insert an explicit cast to silence this issue}}
}
template void f<float>(int); // expected-note{{in instantiation of function template specialization 'PR12453::f<float>' requested here}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x-fixits.cpp
|
// RUN: %clang_cc1 -fsyntax-only -Wc++11-compat -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
// Verify that the appropriate fixits are emitted for narrowing conversions in
// initializer lists.
typedef short int16_t;
void fixits() {
int x = 999;
struct {char c;} c2 = {x};
// CHECK: warning:{{.*}} cannot be narrowed
// CHECK: fix-it:{{.*}}:26}:"static_cast<char>("
// CHECK: fix-it:{{.*}}:27}:")"
struct {int16_t i;} i16 = {70000};
// CHECK: warning:{{.*}} cannot be narrowed
// CHECK: fix-it:{{.*}}:30}:"static_cast<int16_t>("
// CHECK: fix-it:{{.*}}:35}:")"
}
template<typename T>
void maybe_shrink_int(T t) {
struct {T t;} t2 = {700};
}
void test_template() {
maybe_shrink_int((char)3);
// CHECK: warning:{{.*}} cannot be narrowed
// CHECK: note:{{.*}} in instantiation
// CHECK: note:{{.*}} silence
// FIXME: This should be static_cast<T>.
// CHECK: fix-it:{{.*}}"static_cast<char>("
// CHECK: fix-it:{{.*}}")"
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -triple x86_64-apple-macosx10.6.7 -verify %s
// Verify that narrowing conversions in initializer lists cause errors in C++0x
// mode.
void std_example() {
int x = 999; // x is not a constant expression
const int y = 999;
const int z = 99;
char c1 = x; // OK, though it might narrow (in this case, it does narrow)
char c2{x}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
char c3{y}; // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
char c4{z}; // OK: no narrowing needed
unsigned char uc1 = {5}; // OK: no narrowing needed
unsigned char uc2 = {-1}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
unsigned int ui1 = {-1}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
signed int si1 =
{ (unsigned int)-1 }; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
int ii = {2.0}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
float f1 { x }; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
float f2 { 7 }; // OK: 7 can be exactly represented as a float
int f(int);
int a[] =
{ 2, f(2), f(2.0) }; // OK: the double-to-int conversion is not at the top level
}
// Test each rule individually.
template<typename T>
struct Agg {
T t;
};
template<typename T>
struct Convert {
constexpr Convert(T v) : v(v) {}
constexpr operator T() const { return v; }
T v;
};
template<typename T> Convert<T> ConvertVar();
// C++0x [dcl.init.list]p7: A narrowing conversion is an implicit conversion
//
// * from a floating-point type to an integer type, or
void float_to_int() {
Agg<char> a1 = {1.0F}; // expected-error {{type 'float' cannot be narrowed to 'char'}} expected-note {{silence}}
Agg<char> a2 = {1.0}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> a3 = {1.0L}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
float f = 1.0;
double d = 1.0;
long double ld = 1.0;
Agg<char> a4 = {f}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> a5 = {d}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> a6 = {ld}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> ce1 = { Convert<float>(1.0) }; // expected-error {{type 'float' cannot be narrowed to 'char'}} expected-note {{silence}}
Agg<char> ce2 = { ConvertVar<double>() }; // expected-error {{type 'double' cannot be narrowed to 'char'}} expected-note {{silence}}
bool b{1.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}}
Agg<bool> ab = {0.0}; // expected-error {{type 'double' cannot be narrowed to 'bool'}} expected-note {{silence}}
}
// * from long double to double or float, or from double to float, except where
// the source is a constant expression and the actual value after conversion
// is within the range of values that can be represented (even if it cannot be
// represented exactly), or
void shrink_float() {
// These aren't constant expressions.
float f = 1.0;
double d = 1.0;
long double ld = 1.0;
// Variables.
Agg<float> f1 = {f}; // OK (no-op)
Agg<float> f2 = {d}; // expected-error {{non-constant-expression cannot be narrowed from type 'double' to 'float'}} expected-note {{silence}}
Agg<float> f3 = {ld}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// Exact constants.
Agg<float> f4 = {1.0}; // OK (double constant represented exactly)
Agg<float> f5 = {1.0L}; // OK (long double constant represented exactly)
// Inexact but in-range constants.
Agg<float> f6 = {0.1}; // OK (double constant in range but rounded)
Agg<float> f7 = {0.1L}; // OK (long double constant in range but rounded)
// Out of range constants.
Agg<float> f8 = {1E50}; // expected-error {{constant expression evaluates to 1.000000e+50 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<float> f9 = {1E50L}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// More complex constant expression.
constexpr long double e40 = 1E40L, e30 = 1E30L, e39 = 1E39L;
Agg<float> f10 = {e40 - 5 * e39 + e30 - 5 * e39}; // OK
// Variables.
Agg<double> d1 = {f}; // OK (widening)
Agg<double> d2 = {d}; // OK (no-op)
Agg<double> d3 = {ld}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// Exact constant.
Agg<double> d4 = {1.0L}; // OK (long double constant represented exactly)
// Inexact but in-range constant.
Agg<double> d5 = {0.1L}; // OK (long double constant in range but rounded)
// Out of range constant.
Agg<double> d6 = {1E315L}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// More complex constant expression.
constexpr long double e315 = 1E315L, e305 = 1E305L, e314 = 1E314L;
Agg<double> d7 = {e315 - 5 * e314 + e305 - 5 * e314}; // OK
Agg<float> ce1 = { Convert<double>(1e300) }; // expected-error {{constant expression evaluates to 1.000000e+300 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<double> ce2 = { ConvertVar<long double>() }; // expected-error {{non-constant-expression cannot be narrowed from type 'long double' to 'double'}} expected-note {{silence}}
}
// * from an integer type or unscoped enumeration type to a floating-point type,
// except where the source is a constant expression and the actual value after
// conversion will fit into the target type and will produce the original
// value when converted back to the original type, or
void int_to_float() {
// Not a constant expression.
char c = 1;
// Variables. Yes, even though all char's will fit into any floating type.
Agg<float> f1 = {c}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<double> f2 = {c}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<long double> f3 = {c}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// Constants.
Agg<float> f4 = {12345678}; // OK (exactly fits in a float)
Agg<float> f5 = {123456789}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<float> ce1 = { Convert<int>(123456789) }; // expected-error {{constant expression evaluates to 123456789 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<double> ce2 = { ConvertVar<long long>() }; // expected-error {{non-constant-expression cannot be narrowed from type 'long long' to 'double'}} expected-note {{silence}}
}
// * from an integer type or unscoped enumeration type to an integer type that
// cannot represent all the values of the original type, except where the
// source is a constant expression and the actual value after conversion will
// fit into the target type and will produce the original value when converted
// back to the original type.
void shrink_int() {
// Not a constant expression.
short s = 1;
unsigned short us = 1;
Agg<char> c1 = {s}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<unsigned short> s1 = {s}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<short> s2 = {us}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// "that cannot represent all the values of the original type" means that the
// validity of the program depends on the relative sizes of integral types.
// This test compiles with -m64, so sizeof(int)<sizeof(long)==sizeof(long
// long).
long l1 = 1;
Agg<int> i1 = {l1}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
long long ll = 1;
Agg<long> l2 = {ll}; // OK
// Constants.
Agg<char> c2 = {127}; // OK
Agg<char> c3 = {300}; // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
Agg<int> i2 = {0x7FFFFFFFU}; // OK
Agg<int> i3 = {0x80000000U}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<unsigned int> i4 = {-0x80000000L}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// Bool is also an integer type, but conversions to it are a different AST
// node.
Agg<bool> b1 = {0}; // OK
Agg<bool> b2 = {1}; // OK
Agg<bool> b3 = {-1}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
// Conversions from pointers to booleans aren't narrowing conversions.
Agg<bool>* ptr = &b1;
Agg<bool> b = {ptr}; // OK
Agg<short> ce1 = { Convert<int>(100000) }; // expected-error {{constant expression evaluates to 100000 which cannot be narrowed to type 'short'}} expected-note {{silence}} expected-warning {{changes value from 100000 to -31072}}
Agg<char> ce2 = { ConvertVar<short>() }; // expected-error {{non-constant-expression cannot be narrowed from type 'short' to 'char'}} expected-note {{silence}}
// Negative -> larger unsigned type.
unsigned long long ll1 = { -1 }; // expected-error {{ -1 which cannot be narrowed}} expected-note {{silence}}
unsigned long long ll2 = { 1 }; // OK
unsigned long long ll3 = { s }; // expected-error {{cannot be narrowed from type 'short'}} expected-note {{silence}}
unsigned long long ll4 = { us }; // OK
unsigned long long ll5 = { ll }; // expected-error {{cannot be narrowed from type 'long long'}} expected-note {{silence}}
Agg<unsigned long long> ll6 = { -1 }; // expected-error {{ -1 which cannot be narrowed}} expected-note {{silence}}
Agg<unsigned long long> ll7 = { 18446744073709551615ULL }; // OK
Agg<unsigned long long> ll8 = { __int128(18446744073709551615ULL) + 1 }; // expected-error {{ 18446744073709551616 which cannot be narrowed}} expected-note {{silence}} expected-warning {{changes value}}
signed char c = 'x';
unsigned short usc1 = { c }; // expected-error {{non-constant-expression cannot be narrowed from type 'signed char'}} expected-note {{silence}}
unsigned short usc2 = { (signed char)'x' }; // OK
unsigned short usc3 = { (signed char)-1 }; // expected-error {{ -1 which cannot be narrowed}} expected-note {{silence}}
}
// Be sure that type- and value-dependent expressions in templates get the error
// too.
template<int I, typename T>
void maybe_shrink_int(T t) {
Agg<short> s1 = {t}; // expected-error {{ cannot be narrowed }} expected-note {{silence}}
Agg<short> s2 = {I}; // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
Agg<T> t2 = {700}; // expected-error {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
}
void test_template() {
maybe_shrink_int<15>((int)3); // expected-note {{in instantiation}}
maybe_shrink_int<70000>((char)3); // expected-note {{in instantiation}}
}
// We don't want qualifiers on the types in the diagnostic.
void test_qualifiers(int i) {
const int j = i;
struct {const unsigned char c;} c1 = {j}; // expected-error {{from type 'int' to 'unsigned char' in}} expected-note {{silence}}
// Template arguments make it harder to avoid printing qualifiers:
Agg<const unsigned char> c2 = {j}; // expected-error {{from type 'int' to 'const unsigned char' in}} expected-note {{silence}}
}
// Test SFINAE checks.
template<unsigned> struct Value { };
template<typename T>
int &check_narrowed(Value<sizeof((T){1.1})>);
template<typename T>
float &check_narrowed(...);
void test_narrowed(Value<sizeof(int)> vi, Value<sizeof(double)> vd) {
int &ir = check_narrowed<double>(vd);
float &fr = check_narrowed<int>(vi);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p3-0x.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
namespace std {
typedef decltype(sizeof(int)) size_t;
template <typename E>
struct initializer_list
{
const E *p;
size_t n;
initializer_list(const E *p, size_t n) : p(p), n(n) {}
};
struct string {
string(const char *);
};
template<typename A, typename B>
struct pair {
pair(const A&, const B&);
};
}
namespace bullet1 {
double ad[] = { 1, 2.0 };
int ai[] = { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
struct S2 {
int m1;
double m2, m3;
};
S2 s21 = { 1, 2, 3.0 };
S2 s22 { 1.0, 2, 3 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
S2 s23 { };
}
namespace bullet4_example1 {
struct S {
S(std::initializer_list<double> d) {}
S(std::initializer_list<int> i) {}
S() {}
};
S s1 = { 1.0, 2.0, 3.0 };
S s2 = { 1, 2, 3 };
S s3 = { };
}
namespace bullet4_example2 {
struct Map {
Map(std::initializer_list<std::pair<std::string,int>>) {}
};
Map ship = {{"Sophie",14}, {"Surprise",28}};
}
namespace bullet4_example3 {
struct S {
S(int, double, double) {}
S() {}
};
S s1 = { 1, 2, 3.0 };
S s2 { 1.0, 2, 3 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
S s3 {};
}
namespace bullet5 {
int x1 {2};
int x2 {2.0}; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
}
namespace bullet6 {
struct S {
S(std::initializer_list<double>) {}
S(const std::string &) {}
};
const S& r1 = { 1, 2, 3.0 };
const S& r2 = { "Spinach" };
S& r3 = { 1, 2, 3 }; // expected-error {{non-const lvalue reference to type 'bullet6::S' cannot bind to an initializer list temporary}}
const int& i1 = { 1 };
const int& i2 = { 1.1 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}} expected-warning {{implicit conversion}}
const int (&iar)[2] = { 1, 2 };
}
namespace bullet7 {
int** pp {};
}
namespace bullet8 {
struct A { int i; int j; };
A a1 { 1, 2 };
A a2 { 1.2 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}} expected-warning {{implicit conversion}}
struct B {
B(std::initializer_list<int> i) {}
};
B b1 { 1, 2 };
B b2 { 1, 2.0 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}}
struct C {
C(int i, double j) {}
};
C c1 = { 1, 2.2 };
// FIXME: Suppress the narrowing warning in the cases where we issue a narrowing error.
C c2 = { 1.1, 2 }; // expected-error {{type 'double' cannot be narrowed to 'int' in initializer list}} expected-note {{silence}} expected-warning {{implicit conversion}}
int j { 1 };
int k { };
}
namespace rdar13395022 {
struct MoveOnly { // expected-note {{candidate}}
MoveOnly(MoveOnly&&); // expected-note 2{{copy constructor is implicitly deleted because}} expected-note {{candidate}}
};
void test(MoveOnly mo) {
auto &&list1 = {mo}; // expected-error {{call to implicitly-deleted copy constructor}} expected-note {{in initialization of temporary of type 'std::initializer_list}}
MoveOnly (&&list2)[1] = {mo}; // expected-error {{call to implicitly-deleted copy constructor}} expected-note {{in initialization of temporary of type 'rdar13395022::MoveOnly [1]'}}
std::initializer_list<MoveOnly> &&list3 = {};
MoveOnly (&&list4)[1] = {}; // expected-error {{no matching constructor}}
// expected-note@-1 {{in implicit initialization of array element 0 with omitted initializer}}
// expected-note@-2 {{in initialization of temporary of type 'rdar13395022::MoveOnly [1]' created to list-initialize this reference}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-cxx11-nowarn.cpp
|
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-error=c++11-narrowing -triple x86_64-apple-macosx10.6.7 -verify %s
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wno-error=narrowing -triple x86_64-apple-macosx10.6.7 -verify %s
// Verify that narrowing conversions in initializer lists cause errors in C++0x
// mode.
void std_example() {
int x = 999; // x is not a constant expression
const int y = 999;
const int z = 99;
char c1 = x; // OK, though it might narrow (in this case, it does narrow)
char c2{x}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
char c3{y}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
char c4{z}; // OK: no narrowing needed
unsigned char uc1 = {5}; // OK: no narrowing needed
unsigned char uc2 = {-1}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
unsigned int ui1 = {-1}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
signed int si1 =
{ (unsigned int)-1 }; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
int ii = {2.0}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
float f1 { x }; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
float f2 { 7 }; // OK: 7 can be exactly represented as a float
int f(int);
int a[] =
{ 2, f(2), f(2.0) }; // OK: the double-to-int conversion is not at the top level
}
// Test each rule individually.
template<typename T>
struct Agg {
T t;
};
template<typename T>
struct Convert {
constexpr Convert(T v) : v(v) {}
constexpr operator T() const { return v; }
T v;
};
template<typename T> Convert<T> ConvertVar();
// C++0x [dcl.init.list]p7: A narrowing conversion is an implicit conversion
//
// * from a floating-point type to an integer type, or
void float_to_int() {
Agg<char> a1 = {1.0F}; // expected-warning {{type 'float' cannot be narrowed to 'char'}} expected-note {{silence}}
Agg<char> a2 = {1.0}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> a3 = {1.0L}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
float f = 1.0;
double d = 1.0;
long double ld = 1.0;
Agg<char> a4 = {f}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> a5 = {d}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> a6 = {ld}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<char> ce1 = { Convert<float>(1.0) }; // expected-warning {{type 'float' cannot be narrowed to 'char'}} expected-note {{silence}}
Agg<char> ce2 = { ConvertVar<double>() }; // expected-warning {{type 'double' cannot be narrowed to 'char'}} expected-note {{silence}}
}
// * from long double to double or float, or from double to float, except where
// the source is a constant expression and the actual value after conversion
// is within the range of values that can be represented (even if it cannot be
// represented exactly), or
void shrink_float() {
// These aren't constant expressions.
float f = 1.0;
double d = 1.0;
long double ld = 1.0;
// Variables.
Agg<float> f1 = {f}; // OK (no-op)
Agg<float> f2 = {d}; // expected-warning {{non-constant-expression cannot be narrowed from type 'double' to 'float'}} expected-note {{silence}}
Agg<float> f3 = {ld}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// Exact constants.
Agg<float> f4 = {1.0}; // OK (double constant represented exactly)
Agg<float> f5 = {1.0L}; // OK (long double constant represented exactly)
// Inexact but in-range constants.
Agg<float> f6 = {0.1}; // OK (double constant in range but rounded)
Agg<float> f7 = {0.1L}; // OK (long double constant in range but rounded)
// Out of range constants.
Agg<float> f8 = {1E50}; // expected-warning {{constant expression evaluates to 1.000000e+50 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<float> f9 = {1E50L}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// More complex constant expression.
constexpr long double e40 = 1E40L, e30 = 1E30L, e39 = 1E39L;
Agg<float> f10 = {e40 - 5 * e39 + e30 - 5 * e39}; // OK
// Variables.
Agg<double> d1 = {f}; // OK (widening)
Agg<double> d2 = {d}; // OK (no-op)
Agg<double> d3 = {ld}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// Exact constant.
Agg<double> d4 = {1.0L}; // OK (long double constant represented exactly)
// Inexact but in-range constant.
Agg<double> d5 = {0.1L}; // OK (long double constant in range but rounded)
// Out of range constant.
Agg<double> d6 = {1E315L}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// More complex constant expression.
constexpr long double e315 = 1E315L, e305 = 1E305L, e314 = 1E314L;
Agg<double> d7 = {e315 - 5 * e314 + e305 - 5 * e314}; // OK
Agg<float> ce1 = { Convert<double>(1e300) }; // expected-warning {{constant expression evaluates to 1.000000e+300 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<double> ce2 = { ConvertVar<long double>() }; // expected-warning {{non-constant-expression cannot be narrowed from type 'long double' to 'double'}} expected-note {{silence}}
}
// * from an integer type or unscoped enumeration type to a floating-point type,
// except where the source is a constant expression and the actual value after
// conversion will fit into the target type and will produce the original
// value when converted back to the original type, or
void int_to_float() {
// Not a constant expression.
char c = 1;
// Variables. Yes, even though all char's will fit into any floating type.
Agg<float> f1 = {c}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<double> f2 = {c}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<long double> f3 = {c}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// Constants.
Agg<float> f4 = {12345678}; // OK (exactly fits in a float)
Agg<float> f5 = {123456789}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<float> ce1 = { Convert<int>(123456789) }; // expected-warning {{constant expression evaluates to 123456789 which cannot be narrowed to type 'float'}} expected-note {{silence}}
Agg<double> ce2 = { ConvertVar<long long>() }; // expected-warning {{non-constant-expression cannot be narrowed from type 'long long' to 'double'}} expected-note {{silence}}
}
// * from an integer type or unscoped enumeration type to an integer type that
// cannot represent all the values of the original type, except where the
// source is a constant expression and the actual value after conversion will
// fit into the target type and will produce the original value when converted
// back to the original type.
void shrink_int() {
// Not a constant expression.
short s = 1;
unsigned short us = 1;
Agg<char> c1 = {s}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<unsigned short> s1 = {s}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<short> s2 = {us}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// "that cannot represent all the values of the original type" means that the
// validity of the program depends on the relative sizes of integral types.
// This test compiles with -m64, so sizeof(int)<sizeof(long)==sizeof(long
// long).
long l1 = 1;
Agg<int> i1 = {l1}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
long long ll = 1;
Agg<long> l2 = {ll}; // OK
// Constants.
Agg<char> c2 = {127}; // OK
Agg<char> c3 = {300}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
Agg<int> i2 = {0x7FFFFFFFU}; // OK
Agg<int> i3 = {0x80000000U}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<unsigned int> i4 = {-0x80000000L}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// Bool is also an integer type, but conversions to it are a different AST
// node.
Agg<bool> b1 = {0}; // OK
Agg<bool> b2 = {1}; // OK
Agg<bool> b3 = {-1}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
// Conversions from pointers to booleans aren't narrowing conversions.
Agg<bool>* ptr = &b1;
Agg<bool> b = {ptr}; // OK
Agg<short> ce1 = { Convert<int>(100000) }; // expected-warning {{constant expression evaluates to 100000 which cannot be narrowed to type 'short'}} expected-note {{silence}} expected-warning {{changes value from 100000 to -31072}}
Agg<char> ce2 = { ConvertVar<short>() }; // expected-warning {{non-constant-expression cannot be narrowed from type 'short' to 'char'}} expected-note {{silence}}
}
// Be sure that type- and value-dependent expressions in templates get the warning
// too.
template<int I, typename T>
void maybe_shrink_int(T t) {
Agg<short> s1 = {t}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}}
Agg<short> s2 = {I}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
Agg<T> t2 = {700}; // expected-warning {{ cannot be narrowed }} expected-note {{silence}} expected-warning {{changes value}}
}
void test_template() {
maybe_shrink_int<15>((int)3); // expected-note {{in instantiation}}
maybe_shrink_int<70000>((char)3); // expected-note {{in instantiation}}
}
// We don't want qualifiers on the types in the diagnostic.
void test_qualifiers(int i) {
const int j = i;
struct {const unsigned char c;} c1 = {j}; // expected-warning {{from type 'int' to 'unsigned char' in}} expected-note {{silence}}
// Template arguments make it harder to avoid printing qualifiers:
Agg<const unsigned char> c2 = {j}; // expected-warning {{from type 'int' to 'const unsigned char' in}} expected-note {{silence}}
}
// Make sure we still get the right SFINAE behavior.
template<unsigned> struct Value { };
template<typename T>
int &check_narrowed(Value<sizeof((T){1.1})>);
template<typename T>
float &check_narrowed(...);
void test_narrowed(Value<sizeof(int)> vi, Value<sizeof(double)> vd) {
int &ir = check_narrowed<double>(vd);
float &fr = check_narrowed<int>(vi);
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
char test1[1]="f"; // expected-error {{initializer-string for char array is too long}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.string/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
char x1[]("hello");
extern char x1[6];
char x2[] = "hello";
extern char x2[6];
char x3[] = { "hello" };
extern char x3[6];
wchar_t x4[](L"hello");
extern wchar_t x4[6];
wchar_t x5[] = L"hello";
extern wchar_t x5[6];
wchar_t x6[] = { L"hello" };
extern wchar_t x6[6];
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/basic.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
// PR5787
class C {
public:
~C() {}
};
template <typename T>
class E {
public:
E& Foo(const C&);
E& Bar() { return Foo(C()); }
};
void Test() {
E<int> e;
e.Bar();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-examples.cpp
|
// RUN: %clang_cc1 -ast-dump %s 2>&1 | FileCheck %s
// CHECK: example0
void example0() {
double d = 2.0;
// CHECK: VarDecl{{.*}}rd 'double &'
// CHECK-NEXT: DeclRefExpr
double &rd = d;
// CHECK: VarDecl{{.*}}rcd 'const double &'
// CHECK-NEXT: ImplicitCastExpr{{.*}}'const double' lvalue <NoOp>
const double &rcd = d;
}
struct A { };
struct B : A { } b;
// CHECK: example1
void example1() {
// CHECK: VarDecl{{.*}}ra 'struct A &'
// CHECK: ImplicitCastExpr{{.*}}'struct A' lvalue <DerivedToBase (A)>
A &ra = b;
// CHECK: VarDecl{{.*}}rca 'const struct A &'
// CHECK: ImplicitCastExpr{{.*}}'const struct A' lvalue <NoOp>
// CHECK: ImplicitCastExpr{{.*}}'struct A' lvalue <DerivedToBase (A)>
const A& rca = b;
}
extern B f();
struct X {
operator B();
} x;
// CHECK: example2
void example2() {
// CHECK: VarDecl{{.*}}rca 'const struct A &'
// CHECK: ImplicitCastExpr{{.*}}'const struct A' <NoOp>
// CHECK: ImplicitCastExpr{{.*}}'struct A' <DerivedToBase (A)>
// CHECK: CallExpr{{.*}}B
const A &rca = f();
// CHECK: VarDecl{{.*}}r 'const struct A &'
// CHECK: ImplicitCastExpr{{.*}}'const struct A' <NoOp>
// CHECK: ImplicitCastExpr{{.*}}'struct A' <DerivedToBase (A)>
// CHECK: CXXMemberCallExpr{{.*}}'struct B'
const A& r = x;
}
// CHECK: example3
void example3() {
// CHECK: VarDecl{{.*}}rcd2 'const double &'
// CHECK: ImplicitCastExpr{{.*}} <IntegralToFloating>
const double& rcd2 = 2;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-0x.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -pedantic %s
// Test the c++0x-specific reference initialization rules, e.g., the
// rules for rvalue references.
template<typename T> T prvalue();
template<typename T> T&& xvalue();
template<typename T> T& lvalue();
struct Base { };
struct Derived : Base { };
struct HasArray {
int array[5];
};
int f(int);
template<typename T>
struct ConvertsTo {
operator T(); // expected-note 2{{candidate function}}
};
void test_rvalue_refs() {
// If the initializer expression...
// - is an xvalue, class prvalue, array prvalue or function lvalue
// and "cv1 T1" is reference-compatible with "cv2 T2", or
// xvalue case
Base&& base0 = xvalue<Base>();
Base&& base1 = xvalue<Derived>();
int&& int0 = xvalue<int>();
// class prvalue case
Base&& base2 = prvalue<Base>();
Base&& base3 = prvalue<Derived>();
// array prvalue case
int (&&array0)[5] = HasArray().array;
// function lvalue case
int (&&function0)(int) = f;
// - has a class type (i.e., T2 is a class type), where T1 is not
// reference-related to T2, and can be implicitly converted to
// an xvalue, class prvalue, or function lvalue of type "cv3
// T3", where "cv1 T1" is reference-compatible with "cv3 T3",
// xvalue
Base&& base4 = ConvertsTo<Base&&>();
Base&& base5 = ConvertsTo<Derived&&>();
int && int1 = ConvertsTo<int&&>();
// class prvalue
Base&& base6 = ConvertsTo<Base>();
Base&& base7 = ConvertsTo<Derived>();
// function lvalue
int (&&function1)(int) = ConvertsTo<int(&)(int)>();
// In the second case, if the reference is an rvalue reference and
// the second standard conversion sequence of the user-defined
// conversion sequence includes an lvalue-to-rvalue conversion, the
// program is ill-formed.
int &&int2 = ConvertsTo<int&>(); // expected-error{{no viable conversion from 'ConvertsTo<int &>' to 'int'}}
int &&int3 = ConvertsTo<float&>(); // expected-error{{no viable conversion from 'ConvertsTo<float &>' to 'int'}}
}
class NonCopyable {
NonCopyable(const NonCopyable&);
};
class NonCopyableDerived : public NonCopyable {
NonCopyableDerived(const NonCopyableDerived&);
};
// Make sure we get direct bindings with no copies.
void test_direct_binding() {
NonCopyable &&nc0 = prvalue<NonCopyable>();
NonCopyable &&nc1 = prvalue<NonCopyableDerived>();
NonCopyable &&nc2 = xvalue<NonCopyable>();
NonCopyable &&nc3 = xvalue<NonCopyableDerived>();
const NonCopyable &nc4 = prvalue<NonCopyable>();
const NonCopyable &nc5 = prvalue<NonCopyableDerived>();
const NonCopyable &nc6 = xvalue<NonCopyable>();
const NonCopyable &nc7 = xvalue<NonCopyableDerived>();
NonCopyable &&nc8 = ConvertsTo<NonCopyable&&>();
NonCopyable &&nc9 = ConvertsTo<NonCopyableDerived&&>();
const NonCopyable &nc10 = ConvertsTo<NonCopyable&&>();
const NonCopyable &nc11 = ConvertsTo<NonCopyableDerived&&>();
}
namespace std_example_1 {
double d = 2.0;
double& rd = d;
const double& rcd = d;
struct A { };
struct B : A {
operator int&();
} b;
A& ra = b;
const A& rca = b;
int& ir = B();
}
namespace std_example_2 {
double& rd2 = 2.0; // expected-error{{non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'}}
int i = 2;
double& rd3 = i; // expected-error{{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}}
struct A { };
struct B : A { } b;
extern B f();
const A& rca = f();
A&& rra = f();
struct X {
operator B(); // expected-note{{candidate function}}
operator int&(); // expected-note{{candidate function}}
} x;
const A& r = x;
int&& rri = static_cast<int&&>(i);
B&& rrb = x;
int&& rri2 = X(); // expected-error{{no viable conversion from 'std_example_2::X' to 'int'}}
const double& rcd2 = 2;
double&& rrd = 2;
const volatile int cvi = 1;
const int& r2 = cvi; // expected-error{{binding value of type 'const volatile int' to reference to type 'const int' drops 'volatile' qualifier}}
double d;
double&& rrd2 = d; // expected-error{{rvalue reference to type 'double' cannot bind to lvalue of type 'double'}}
double&& rrd3 = i;
}
namespace argument_passing {
void base_rvalue_ref(Base&&);
void int_rvalue_ref(int&&); // expected-note{{candidate function not viable: no known conversion from 'ConvertsTo<int &>' to 'int &&' for 1st argument}} \
// expected-note{{candidate function not viable: no known conversion from 'ConvertsTo<float &>' to 'int &&' for 1st argument}}
void array_rvalue_ref(int (&&)[5]);
void function_rvalue_ref(int (&&)(int));
void test() {
base_rvalue_ref(xvalue<Base>());
base_rvalue_ref(xvalue<Derived>());
int_rvalue_ref(xvalue<int>());
base_rvalue_ref(prvalue<Base>());
base_rvalue_ref(prvalue<Derived>());
array_rvalue_ref(HasArray().array);
function_rvalue_ref(f);
base_rvalue_ref(ConvertsTo<Base&&>());
base_rvalue_ref(ConvertsTo<Derived&&>());
int_rvalue_ref(ConvertsTo<int&&>());
base_rvalue_ref(ConvertsTo<Base>());
base_rvalue_ref(ConvertsTo<Derived>());
function_rvalue_ref(ConvertsTo<int(&)(int)>());
int_rvalue_ref(ConvertsTo<int&>()); // expected-error{{no matching function for call to 'int_rvalue_ref'}}
int_rvalue_ref(ConvertsTo<float&>()); // expected-error{{no matching function for call to 'int_rvalue_ref'}}
}
}
namespace pr10644 {
struct string {
string(const char* __s);
};
class map {
int& operator[](const string& __k);
public:
int& operator[](const string&& __k);
};
void foo() {
static map key_map;
key_map["line"];
}
}
namespace PR11003 {
class Value {
};
struct MoveRef {
operator Value &() const ;
};
MoveRef Move(int);
void growTo() {
Value x = Move(0);
Value y(Move(0));
}
}
namespace rdar13278115 {
struct X { };
struct Y : X { };
X &&f0(X &x) { return x; } // expected-error{{rvalue reference to type 'rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::X'}}
X &&f1(Y &y) { return y; } // expected-error{{rvalue reference to type 'rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::Y'}}
const X &&f2(Y &y) { return y; } // expected-error{{rvalue reference to type 'const rdar13278115::X' cannot bind to lvalue of type 'rdar13278115::Y'}}
}
namespace bitfields {
struct IntBitfield {
int i : 17; // expected-note 3 {{bit-field is declared here}}
};
// A simplified version of std::move.
template <typename T>
T &&move(T &obj) {
return static_cast<T &&>(obj);
}
void test() {
int & ir1 = (lvalue<IntBitfield>().i); // expected-error{{non-const reference cannot bind to bit-field 'i'}}
int & ir2 = (xvalue<IntBitfield>().i); // expected-error{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
int && ir3 = (xvalue<IntBitfield>().i); // no-warning
int && ir4 = move(lvalue<IntBitfield>()).i; // no-warning
volatile int & vir1 = (lvalue<IntBitfield>().i); // expected-error{{non-const reference cannot bind to bit-field 'i'}}
volatile int & vir2 = (xvalue<IntBitfield>().i); // expected-error{{volatile lvalue reference to type 'volatile int' cannot bind to a temporary of type 'int'}}
volatile int && vir3 = (xvalue<IntBitfield>().i); // no-warning
volatile int && vir4 = move(lvalue<IntBitfield>()).i; // no-warning
const int & cir1 = (lvalue<IntBitfield>().i); // no-warning
const int & cir2 = (xvalue<IntBitfield>().i); // no-warning
const int && cir3 = (xvalue<IntBitfield>().i); // no-warning
const int && cir4 = move(lvalue<IntBitfield>()).i; // no-warning
const volatile int & cvir1 = (lvalue<IntBitfield>().i); // expected-error{{non-const reference cannot bind to bit-field 'i'}}
const volatile int & cvir2 = (xvalue<IntBitfield>().i); // expected-error{{volatile lvalue reference to type 'const volatile int' cannot bind to a temporary of type 'int'}}
const volatile int && cvir3 = (xvalue<IntBitfield>().i); // no-warning
const volatile int && cvir4 = move(lvalue<IntBitfield>()).i; // no-warning
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-var.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct Base { };
struct Derived : Base { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable}}
struct Unrelated { };
struct Derived2 : Base { };
struct Diamond : Derived, Derived2 { };
struct ConvertibleToBaseRef {
operator Base&() const;
};
struct ConvertibleToDerivedRef {
operator Derived&() const;
};
struct ConvertibleToBothDerivedRef {
operator Derived&(); // expected-note{{candidate function}}
operator Derived2&(); // expected-note{{candidate function}}
};
struct ConvertibleToIntRef {
operator int&();
};
struct ConvertibleToBase {
operator Base() const;
};
struct ConvertibleToDerived {
operator Derived() const;
};
struct ConvertibleToBothDerived {
operator Derived(); // expected-note{{candidate function}}
operator Derived2(); // expected-note{{candidate function}}
};
struct ConvertibleToInt {
operator int();
};
template<typename T> T create();
// First bullet: lvalue references binding to lvalues (the simple cases).
void bind_lvalue_to_lvalue(Base b, Derived d,
const Base bc, const Derived dc,
Diamond diamond,
int i) {
// Reference-compatible
Base &br1 = b;
Base &br2 = d;
Derived &dr1 = d;
Derived &dr2 = b; // expected-error{{non-const lvalue reference to type 'Derived' cannot bind to a value of unrelated type 'Base'}}
Base &br3 = bc; // expected-error{{drops 'const' qualifier}}
Base &br4 = dc; // expected-error{{drops 'const' qualifier}}
Base &br5 = diamond; // expected-error{{ambiguous conversion from derived class 'Diamond' to base class 'Base':}}
int &ir = i;
long &lr = i; // expected-error{{non-const lvalue reference to type 'long' cannot bind to a value of unrelated type 'int'}}
}
void bind_lvalue_quals(volatile Base b, volatile Derived d,
volatile const Base bvc, volatile const Derived dvc,
volatile const int ivc) {
volatile Base &bvr1 = b;
volatile Base &bvr2 = d;
volatile Base &bvr3 = bvc; // expected-error{{binding value of type 'const volatile Base' to reference to type 'volatile Base' drops 'const' qualifier}}
volatile Base &bvr4 = dvc; // expected-error{{binding value of type 'const volatile Derived' to reference to type 'volatile Base' drops 'const' qualifier}}
volatile int &ir = ivc; // expected-error{{binding value of type 'const volatile int' to reference to type 'volatile int' drops 'const' qualifier}}
const volatile Base &bcvr1 = b;
const volatile Base &bcvr2 = d;
}
void bind_lvalue_to_rvalue() {
Base &br1 = Base(); // expected-error{{non-const lvalue reference to type 'Base' cannot bind to a temporary of type 'Base'}}
Base &br2 = Derived(); // expected-error{{non-const lvalue reference to type 'Base' cannot bind to a temporary of type 'Derived'}}
const volatile Base &br3 = Base(); // expected-error{{volatile lvalue reference to type 'const volatile Base' cannot bind to a temporary of type 'Base'}}
const volatile Base &br4 = Derived(); // expected-error{{volatile lvalue reference to type 'const volatile Base' cannot bind to a temporary of type 'Derived'}}
int &ir = 17; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}}
}
void bind_lvalue_to_unrelated(Unrelated ur) {
Base &br1 = ur; // expected-error{{non-const lvalue reference to type 'Base' cannot bind to a value of unrelated type 'Unrelated'}}
const volatile Base &br2 = ur; // expected-error{{volatile lvalue reference to type 'const volatile Base' cannot bind to a value of unrelated type 'Unrelated'}}
}
void bind_lvalue_to_conv_lvalue() {
// Not reference-related, but convertible
Base &nbr1 = ConvertibleToBaseRef();
Base &nbr2 = ConvertibleToDerivedRef();
Derived &ndr1 = ConvertibleToDerivedRef();
int &ir = ConvertibleToIntRef();
}
void bind_lvalue_to_conv_lvalue_ambig(ConvertibleToBothDerivedRef both) {
Derived &dr1 = both;
Base &br1 = both; // expected-error{{reference initialization of type 'Base &' with initializer of type 'ConvertibleToBothDerivedRef' is ambiguous}}
}
struct IntBitfield {
int i : 17; // expected-note{{bit-field is declared here}}
};
void test_bitfield(IntBitfield ib) {
int & ir1 = (ib.i); // expected-error{{non-const reference cannot bind to bit-field 'i'}}
}
// Second bullet: const lvalue reference binding to an rvalue with
// similar type (both of which are class types).
void bind_const_lvalue_to_rvalue() {
const Base &br1 = create<Base>();
const Base &br2 = create<Derived>();
const Derived &dr1 = create<Base>(); // expected-error{{no viable conversion}}
const Base &br3 = create<const Base>();
const Base &br4 = create<const Derived>();
const Base &br5 = create<const volatile Base>(); // expected-error{{binding value of type 'const volatile Base' to reference to type 'const Base' drops 'volatile' qualifier}}
const Base &br6 = create<const volatile Derived>(); // expected-error{{binding value of type 'const volatile Derived' to reference to type 'const Base' drops 'volatile' qualifier}}
const int &ir = create<int>();
}
// Second bullet: const lvalue reference binds to the result of a conversion.
void bind_const_lvalue_to_class_conv_temporary() {
const Base &br1 = ConvertibleToBase();
const Base &br2 = ConvertibleToDerived();
}
void bind_lvalue_to_conv_rvalue_ambig(ConvertibleToBothDerived both) {
const Derived &dr1 = both;
const Base &br1 = both; // expected-error{{reference initialization of type 'const Base &' with initializer of type 'ConvertibleToBothDerived' is ambiguous}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
int& r1; // expected-error{{declaration of reference variable 'r1' requires an initializer}}
extern int& r2;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// expected-no-diagnostics
int g(int);
void f() {
int i;
int& r = i;
r = 1;
int* p = &r;
int &rr=r;
int (&rg)(int) = g;
rg(i);
int a[3];
int (&ra)[3] = a;
ra[1] = i;
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace PR5909 {
struct Foo {
int x : 20;
};
bool Test(const int& foo);
const Foo f = { 0 }; // It compiles without the 'const'.
bool z = Test(f.x);
}
namespace PR6264 {
typedef int (&T)[3];
struct S
{
operator T ();
};
void f()
{
T bar = S();
}
}
namespace PR6066 {
struct B { };
struct A : B {
operator B*();
operator B&(); // expected-warning{{conversion function converting 'PR6066::A' to its base class 'PR6066::B' will never be used}}
};
void f(B&); // no rvalues accepted
void f(B*);
int g() {
f(A()); // calls f(B*)
return 0;
}
}
namespace test3 {
struct A {
unsigned bitX : 4; // expected-note 4 {{bit-field is declared here}}
unsigned bitY : 4; // expected-note {{bit-field is declared here}}
unsigned var;
void foo();
};
void test(A *a) {
unsigned &t0 = a->bitX; // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
unsigned &t1 = (unsigned&) a->bitX; // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
unsigned &t2 = const_cast<unsigned&>(a->bitX); // expected-error {{const_cast from bit-field lvalue to reference type 'unsigned int &'}}
unsigned &t3 = (a->foo(), a->bitX); // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
unsigned &t4 = (a->var ? a->bitX : a->bitY); // expected-error {{non-const reference cannot bind to bit-field}}
unsigned &t5 = (a->var ? a->bitX : a->bitX); // expected-error {{non-const reference cannot bind to bit-field}}
unsigned &t6 = (a->var ? a->bitX : a->var); // expected-error {{non-const reference cannot bind to bit-field}}
unsigned &t7 = (a->var ? a->var : a->bitY); // expected-error {{non-const reference cannot bind to bit-field}}
unsigned &t8 = (a->bitX = 3); // expected-error {{non-const reference cannot bind to bit-field 'bitX'}}
unsigned &t9 = (a->bitY += 3); // expected-error {{non-const reference cannot bind to bit-field 'bitY'}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx03-extra-copy.cpp
|
// RUN: %clang_cc1 -fsyntax-only -fdiagnostics-show-option -Wbind-to-temporary-copy -verify %s
// C++03 requires that we check for a copy constructor when binding a
// reference to a temporary, since we are allowed to make a copy, Even
// though we don't actually make that copy, make sure that we diagnose
// cases where that copy constructor is somehow unavailable. As an
// extension, this is only a warning.
struct X1 {
X1();
explicit X1(const X1&);
};
struct X2 {
X2();
private:
X2(const X2&); // expected-note{{declared private here}}
};
struct X3 {
X3();
private:
X3(X3&); // expected-note{{candidate constructor not viable: expects an l-value for 1st argument}}
};
// Check for instantiation of default arguments
template<typename T>
T get_value_badly() {
double *dp = 0;
// The extension doesn't extend far enough to turn this error into a warning.
T *tp = dp; // expected-error{{cannot initialize a variable of type 'int *' with an lvalue of type 'double *'}}
return T();
}
template<typename T>
struct X4 {
X4();
X4(const X4&, T = get_value_badly<T>()); // expected-note{{in instantiation of}}
};
// Check for "dangerous" default arguments that could cause recursion.
struct X5 {
X5();
X5(const X5&, const X5& = X5()); // expected-warning{{no viable constructor copying parameter of type 'X5'}}
};
void g1(const X1&);
void g2(const X2&);
void g3(const X3&);
void g4(const X4<int>&);
void g5(const X5&);
void test() {
g1(X1());
g2(X2()); // expected-warning{{C++98 requires an accessible copy constructor for class 'X2' when binding a reference to a temporary; was private}}
g3(X3()); // expected-warning{{no viable constructor copying parameter of type 'X3'}}
g4(X4<int>());
g5(X5()); // Generates a warning in the default argument.
}
// Check that unavailable copy constructors still cause SFINAE failures.
template<int> struct int_c { };
template<typename T> T f(const T&);
// Would be ambiguous with the next g(), except the instantiation failure in
// sizeof() prevents that.
template<typename T>
int &g(int_c<sizeof(f(T()))> * = 0);
template<typename T> float &g();
void h() {
float &fp2 = g<X3>(); // Not ambiguous.
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.init/dcl.init.ref/p5-cxx0x-no-extra-copy.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// C++03 requires that we check for a copy constructor when binding a
// reference to a reference-compatible rvalue, since we are allowed to
// make a copy. C++0x does not permit the copy, so ensure that we
// don't diagnose cases where the copy constructor is unavailable.
struct X1 {
X1();
explicit X1(const X1&);
};
struct X2 {
X2();
private:
X2(const X2&);
};
struct X3 {
X3();
private:
X3(X3&);
};
template<typename T>
T get_value_badly() {
double *dp = 0;
T *tp = dp;
return T();
}
template<typename T>
struct X4 {
X4();
X4(const X4&, T = get_value_badly<T>());
};
void g1(const X1&);
void g2(const X2&);
void g3(const X3&);
void g4(const X4<int>&);
void test() {
g1(X1());
g2(X2());
g3(X3());
g4(X4<int>());
}
// Check that unavailable copy constructors do not cause SFINAE failures.
template<int> struct int_c { };
template<typename T> T f(const T&);
template<typename T>
int &g(int_c<sizeof(f(T()))> * = 0); // expected-note{{candidate function [with T = X3]}}
template<typename T> float &g(); // expected-note{{candidate function [with T = X3]}}
void h() {
float &fp = g<X3>(); // expected-error{{call to 'g' is ambiguous}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.delete/p4.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
template<typename> void func();
template<> void func<int>() = delete;
template<typename> void func2();
template<> void func2<int>(); // expected-note {{previous declaration is here}}
template<> void func2<int>() = delete; // expected-error {{deleted definition must be first declaration}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.general/p8.cpp
|
// RUN: %clang_cc1 -std=c++11 %s -verify
// expected-no-diagnostics
using size_t = decltype(sizeof(0));
template<typename T> struct check;
template<size_t N> struct check<const char[N]> {};
constexpr bool startswith(const char *p, const char *q) {
return !*q || (*p == *q && startswith(p + 1, q + 1));
}
constexpr bool contains(const char *p, const char *q) {
return *p && (startswith(p, q) || contains(p + 1, q));
}
void foo() {
check<decltype(__func__)>();
static_assert(contains(__func__, "foo"), "");
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -fcxx-exceptions %s
// An explicitly-defaulted function may be declared constexpr only if it would
// have been implicitly declared as constexpr.
struct S1 {
constexpr S1() = default; // expected-error {{defaulted definition of default constructor is not constexpr}}
constexpr S1(const S1&) = default;
constexpr S1(S1&&) = default;
constexpr S1 &operator=(const S1&) const = default; // expected-error {{explicitly-defaulted copy assignment operator may not have}}
constexpr S1 &operator=(S1&&) const = default; // expected-error {{explicitly-defaulted move assignment operator may not have}}
constexpr ~S1() = default; // expected-error {{destructor cannot be marked constexpr}}
int n;
};
struct NoCopyMove {
constexpr NoCopyMove() {}
NoCopyMove(const NoCopyMove&);
NoCopyMove(NoCopyMove&&);
};
struct S2 {
constexpr S2() = default;
constexpr S2(const S2&) = default; // expected-error {{defaulted definition of copy constructor is not constexpr}}
constexpr S2(S2&&) = default; // expected-error {{defaulted definition of move constructor is not constexpr}}
NoCopyMove ncm;
};
// If a function is explicitly defaulted on its first declaration
// -- it is implicitly considered to be constexpr if the implicit declaration
// would be
struct S3 {
S3() = default;
S3(const S3&) = default;
S3(S3&&) = default;
constexpr S3(int n) : n(n) {}
int n;
};
constexpr S3 s3a = S3(0);
constexpr S3 s3b = s3a;
constexpr S3 s3c = S3();
constexpr S3 s3d; // expected-error {{default initialization of an object of const type 'const S3' without a user-provided default constructor}}
struct S4 {
S4() = default;
S4(const S4&) = default; // expected-note {{here}}
S4(S4&&) = default; // expected-note {{here}}
NoCopyMove ncm;
};
constexpr S4 s4a{}; // ok
constexpr S4 s4b = S4(); // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
constexpr S4 s4c = s4a; // expected-error {{constant expression}} expected-note {{non-constexpr constructor}}
struct S5 {
constexpr S5();
int n = 1, m = n + 3;
};
constexpr S5::S5() = default;
static_assert(S5().m == 4, "");
// An explicitly-defaulted function may have an exception specification only if
// it is compatible with the exception specification on an implicit declaration.
struct E1 {
E1() noexcept = default;
E1(const E1&) noexcept = default;
E1(E1&&) noexcept = default;
E1 &operator=(const E1&) noexcept = default;
E1 &operator=(E1&&) noexcept = default;
~E1() noexcept = default;
};
struct E2 {
E2() noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted default constructor does not match the calculated one}}
E2(const E2&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted copy constructor does not match the calculated one}}
E2(E2&&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted move constructor does not match the calculated one}}
E2 &operator=(const E2&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted copy assignment operator does not match the calculated one}}
E2 &operator=(E2&&) noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted move assignment operator does not match the calculated one}}
~E2() noexcept(false) = default; // expected-error {{exception specification of explicitly defaulted destructor does not match the calculated one}}
};
// If a function is explicitly defaulted on its first declaration
// -- it is implicitly considered to have the same exception-specification as
// if it had been implicitly declared
struct E3 {
E3() = default;
E3(const E3&) = default;
E3(E3&&) = default;
E3 &operator=(const E3&) = default;
E3 &operator=(E3&&) = default;
~E3() = default;
};
E3 e3;
static_assert(noexcept(E3(), E3(E3()), E3(e3), e3 = E3(), e3 = e3), "");
struct E4 {
E4() noexcept(false);
E4(const E4&) noexcept(false);
E4(E4&&) noexcept(false);
E4 &operator=(const E4&) noexcept(false);
E4 &operator=(E4&&) noexcept(false);
~E4() noexcept(false);
};
struct E5 {
E5() = default;
E5(const E5&) = default;
E5(E5&&) = default;
E5 &operator=(const E5&) = default;
E5 &operator=(E5&&) = default;
~E5() = default;
E4 e4;
};
E5 e5;
static_assert(!noexcept(E5()), "");
static_assert(!noexcept(E5(static_cast<E5&&>(e5))), "");
static_assert(!noexcept(E5(e5)), "");
static_assert(!noexcept(e5 = E5()), "");
static_assert(!noexcept(e5 = e5), "");
namespace PR13492 {
struct B {
B() = default;
};
void f() {
const B b; // expected-error {{default initialization of an object of const type 'const PR13492::B' without a user-provided default constructor}}
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p1.cpp
|
// RUN: %clang_cc1 -verify %s -std=c++11
// A function that is explicitly defaulted shall
struct A {
// -- be a special member function,
A(int) = default; // expected-error {{only special member functions may be defaulted}}
// -- have the same declared function type as if it had been implicitly
// declared
void operator=(const A &) = default; // expected-error {{must return 'A &'}}
A(...) = default; // expected-error {{cannot be variadic}}
A(const A &, ...) = default; // expected-error {{cannot be variadic}}
// (except for possibly differing ref-qualifiers
A &operator=(A &&) & = default;
// and except that in the case of a copy constructor or copy assignment
// operator, the parameter type may be "reference to non-const T")
A(A &) = default;
A &operator=(A &) = default;
// -- not have default arguments
A(double = 0.0) = default; // expected-error {{cannot have default arguments}}
A(const A & = 0) = default; // expected-error {{cannot have default arguments}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// The nested-name-specifier of a qualified declarator-id shall not begin with a decltype-specifier.
class foo {
static int i;
void func();
};
int decltype(foo())::i; // expected-error{{'decltype' cannot be used to name a declaration}}
void decltype(foo())::func() { // expected-error{{'decltype' cannot be used to name a declaration}}
}
template<typename T>
class tfoo {
static int i;
void func();
};
template<typename T>
int decltype(tfoo<T>())::i; // expected-error{{nested name specifier 'decltype(tfoo<T>())::' for declaration does not refer into a class, class template or class template partial specialization}}
template<typename T>
void decltype(tfoo<T>())::func() { // expected-error{{nested name specifier 'decltype(tfoo<T>())::' for declaration does not refer into a class, class template or class template partial specialization}}
}
// An init-declarator named with a qualified-id can refer to an element of the
// inline namespace set of the named namespace.
namespace inline_namespaces {
namespace N {
inline namespace M {
void f(); // expected-note {{possible target}}
void g();
extern int m; // expected-note {{candidate}}
extern int n;
struct S; // expected-note {{candidate}}
struct T;
enum E : int; // expected-note {{candidate}}
enum F : int;
template<typename T> void ft(); // expected-note {{here}}
template<typename T> void gt(); // expected-note {{here}}
template<typename T> extern int mt; // expected-note {{here}} expected-warning {{extension}}
template<typename T> extern int nt; // expected-note {{here}} expected-warning {{extension}}
template<typename T> struct U; // expected-note {{here}}
template<typename T> struct V; // expected-note {{here}}
}
// When named by unqualified-id, we do *not* look in the inline namespace
// set.
void f() {} // expected-note {{possible target}}
int m; // expected-note {{candidate}}
struct S {}; // expected-note {{candidate}}
enum E : int {}; // expected-note {{candidate}}
static_assert(&f != &M::f, ""); // expected-error {{reference to overloaded function could not be resolved}}
static_assert(&m != &M::m, ""); // expected-error {{ambiguous}}
typedef S X; // expected-error {{ambiguous}}
typedef E Y; // expected-error {{ambiguous}}
// When named by (unqualified) template-id, we do look in the inline
// namespace set. See [namespace.def]p8, [temp.explicit]p3,
// [temp.expl.spec]p2.
//
// This is not explicitly specified for partial specializations, but
// that is just a language defect.
template<> void ft<int>() {}
template void ft<char>(); // expected-error {{undefined}}
template<typename T> int mt<T*>;
template<> int mt<int>;
template int mt<int*>;
template int mt<char>; // expected-error {{undefined}}
template<typename T> struct U<T*> {};
template<> struct U<int> {};
template struct U<int*>;
template struct U<char>; // expected-error {{undefined}}
}
// When named by qualified-id, we *do* look in the inline namespace set.
void N::g() {}
int N::n;
struct N::T {};
enum N::F : int {};
static_assert(&N::g == &N::M::g, "");
static_assert(&N::n == &N::M::n, "");
typedef N::T X;
typedef N::M::T X;
typedef N::F Y;
typedef N::M::F Y;
template<> void N::gt<int>() {}
template void N::gt<char>(); // expected-error {{undefined}}
template<typename T> int N::nt<T*>;
template<> int N::nt<int>;
template int N::nt<int*>;
template int N::nt<char>; // expected-error {{undefined}}
template<typename T> struct N::V<T*> {};
template<> struct N::V<int> {};
template struct N::V<int*>;
template struct N::V<char>; // expected-error {{undefined}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace PR8019 {
struct x;
template<typename T> struct x2;
struct y {
struct PR8019::x { int x; }; // expected-error{{non-friend class member 'x' cannot have a qualified name}}
struct inner;
struct y::inner { }; // expected-error{{extra qualification on member 'inner'}}
template<typename T>
struct PR8019::x2 { }; // expected-error{{non-friend class member 'x2' cannot have a qualified name}}
template<typename T>
struct inner_template;
template<typename T>
struct y::inner_template { }; // expected-error{{extra qualification on member 'inner_template'}}
};
}
namespace NS {
void foo();
extern int bar;
struct X;
template<typename T> struct Y;
template<typename T> void wibble(T);
struct Z;
}
namespace NS {
// Under DR482, these are all valid, except for forward-declaring a struct
// with a nested-name-specifier.
void NS::foo(); // expected-warning {{extra qualification}}
extern int NS::bar; // expected-warning {{extra qualification}}
struct NS::X; // expected-error {{forward declaration of struct cannot have a nested name specifier}} expected-warning {{extra qualification}}
template<typename T> struct NS::Y; // expected-error {{forward declaration of struct cannot have a nested name specifier}} expected-warning {{extra qualification}}
template<typename T> void NS::wibble(T); // expected-warning {{extra qualification}}
void NS::foo() {} // expected-warning{{extra qualification on member 'foo'}}
int NS::bar; // expected-warning{{extra qualification on member 'bar'}}
struct NS::X { }; // expected-warning{{extra qualification on member 'X'}}
template<typename T> struct NS::Y { }; // expected-warning{{extra qualification on member 'Y'}}
template<typename T> void NS::wibble(T) { } // expected-warning{{extra qualification on member 'wibble'}}
}
struct ::{} a; // expected-error{{expected identifier}}
struct NS::Z:: {} b; // expected-error{{expected identifier}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p6-0x.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
template<typename T, typename U>
struct is_same {
static const bool value = false;
};
template<typename T>
struct is_same<T, T> {
static const bool value = true;
};
#define JOIN2(X,Y) X##Y
#define JOIN(X,Y) JOIN2(X,Y)
#define CHECK_EQUAL_TYPES(T1, T2) \
int JOIN(array,__LINE__)[is_same<T1, T2>::value? 1 : -1]
int i;
typedef int& LRI;
typedef int&& RRI;
typedef LRI& r1; CHECK_EQUAL_TYPES(r1, int&);
typedef const LRI& r2; CHECK_EQUAL_TYPES(r2, int&); // expected-warning {{'const' qualifier on reference type 'LRI' (aka 'int &') has no effect}}
typedef const LRI&& r3; CHECK_EQUAL_TYPES(r3, int&); // expected-warning {{'const' qualifier on reference type 'LRI' (aka 'int &') has no effect}}
typedef RRI& r4; CHECK_EQUAL_TYPES(r4, int&);
typedef RRI&& r5; CHECK_EQUAL_TYPES(r5, int&&);
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.ref/p5.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// C++ [dcl.ref]p5:
// There shall be no references to references, no arrays of
// references, and no pointers to references.
// The crazy formatting in here is to enforce the exact report locations.
typedef int &intref;
typedef intref &intrefref;
template <class T> class RefMem { // expected-warning{{class 'RefMem<int &>' does not declare any constructor to initialize its non-modifiable members}}
T
&
member; // expected-note{{reference member 'member' will never be initialized}}
};
struct RefRef {
int
&
& // expected-error {{declared as a reference to a reference}}
refref0;
intref
&
refref1; // collapses
intrefref
&
refref2; // collapses
RefMem
<
int
&
>
refref3; // collapses expected-note{{in instantiation of template class 'RefMem<int &>' requested here}}
};
template <class T> class PtrMem {
T
* // expected-error {{declared as a pointer to a reference}}
member;
};
struct RefPtr {
typedef
int
&
* // expected-error {{declared as a pointer to a reference}}
intrefptr;
typedef
intref
* // expected-error {{declared as a pointer to a reference}}
intrefptr2;
int
&
* // expected-error {{declared as a pointer to a reference}}
refptr0;
intref
* // expected-error {{declared as a pointer to a reference}}
refptr1;
PtrMem
<
int
&
>
refptr2; // expected-note {{in instantiation}}
};
template <class T> class ArrMem {
T
member
[ // expected-error {{declared as array of references}}
10
];
};
template <class T, unsigned N> class DepArrMem {
T
member
[ // expected-error {{declared as array of references}}
N
];
};
struct RefArr {
typedef
int
&
intrefarr
[ // expected-error {{declared as array of references}}
2
];
typedef
intref
intrefarr
[ // expected-error {{declared as array of references}}
2
];
int
&
refarr0
[ // expected-error {{declared as array of references}}
2
];
intref
refarr1
[ // expected-error {{declared as array of references}}
2
];
ArrMem
<
int
&
>
refarr2; // expected-note {{in instantiation}}
DepArrMem
<
int
&,
10
>
refarr3; // expected-note {{in instantiation}}
};
// The declaration of a reference shall contain an initializer
// (8.5.3) except when the declaration contains an explicit extern
// specifier (7.1.1), is a class member (9.2) declaration within a
// class definition, or is the declaration of a parameter or a
// return type (8.3.5); see 3.1. A reference shall be initialized to
// refer to a valid object or function. [ Note: in particular, a
// null reference cannot exist in a well-defined program, because
// the only way to create such a reference would be to bind it to
// the "object" obtained by dereferencing a null pointer, which
// causes undefined behavior. As described in 9.6, a reference
// cannot be bound directly to a bit-field.
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
auto f() -> int[32]; // expected-error{{function cannot return array}}
auto g() -> int(int); // expected-error{{function cannot return function}}
auto h() -> auto() -> int; // expected-error{{function cannot return function}}
auto i() -> auto(*)() -> int;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p14.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
template<typename T> struct identity;
template<typename ...Types> struct tuple;
template<typename T, typename U> struct is_same {
static const bool value = false;
};
template<typename T> struct is_same<T, T> {
static const bool value = true;
};
// There is a syntactic ambiguity when an ellipsis occurs at the end
// of a parameter-declaration-clause without a preceding comma. In
// this case, the ellipsis is parsed as part of the
// abstract-declarator if the type of the parameter names a template
// parameter pack that has not been expanded; otherwise, it is parsed
// as part of the parameter-declaration-clause.
template<typename T, typename ...Types>
struct X0 {
typedef identity<T(Types...)> function_pack_1;
typedef identity<T(Types......)> variadic_function_pack_1; // expected-warning {{varargs}} expected-note {{pack}} expected-note {{insert ','}}
typedef identity<T(T...)> variadic_1;
typedef tuple<T(Types, ...)...> template_arg_expansion_1;
};
// FIXME: Once function parameter packs are implemented, we can test all of the disambiguation
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p8.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct A { };
A::A (enum { e1 }) {} // expected-error{{cannot be defined in a parameter}}
void A::f(enum { e2 }) {} // expected-error{{cannot be defined in a parameter}}
enum { e3 } A::g() { } // expected-error{{cannot be defined in the result type}} \
// expected-error{{out-of-line definition}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
void f0() &; // expected-error {{non-member function cannot have '&' qualifier}}
void f1() &&; // expected-error {{non-member function cannot have '&&' qualifier}}
void f2() const volatile &&; // expected-error {{non-member function cannot have 'const volatile &&' qualifier}}
struct X {
void f0() &;
void f1() &&;
static void f2() &; // expected-error{{static member function cannot have '&' qualifier}}
static void f3() &&; // expected-error{{static member function cannot have '&&' qualifier}}
};
typedef void func_type_lvalue() &;
typedef void func_type_rvalue() &&;
typedef func_type_lvalue *func_type_lvalue_ptr; // expected-error{{pointer to function type 'func_type_lvalue' (aka 'void () &') cannot have '&' qualifier}}
typedef func_type_rvalue *func_type_rvalue_ptr; // expected-error{{pointer to function type 'func_type_rvalue' (aka 'void () &&') cannot have '&&' qualifier}}
typedef func_type_lvalue &func_type_lvalue_ref; // expected-error{{reference to function type 'func_type_lvalue' (aka 'void () &') cannot have '&' qualifier}}
typedef func_type_rvalue &func_type_rvalue_ref; // expected-error{{reference to function type 'func_type_rvalue' (aka 'void () &&') cannot have '&&' qualifier}}
template<typename T = func_type_lvalue> struct wrap {
typedef T val;
typedef T *ptr; // expected-error-re 2{{pointer to function type '{{.*}}' cannot have '{{&|&&}}' qualifier}}
typedef T &ref; // expected-error-re 2{{reference to function type '{{.*}}' cannot have '{{&|&&}}' qualifier}}
};
using func_type_lvalue = wrap<>::val; // expected-note{{in instantiation of}}
using func_type_lvalue = wrap<func_type_lvalue>::val;
using func_type_rvalue = wrap<func_type_rvalue>::val; // expected-note{{in instantiation of}}
using func_type_lvalue_ptr = wrap<>::ptr;
using func_type_lvalue_ptr = wrap<func_type_lvalue>::ptr;
using func_type_rvalue_ptr = wrap<func_type_rvalue>::ptr;
using func_type_lvalue_ref = wrap<>::ref;
using func_type_lvalue_ref = wrap<func_type_lvalue>::ref;
using func_type_rvalue_ref = wrap<func_type_rvalue>::ref;
func_type_lvalue f2; // expected-error{{non-member function of type 'func_type_lvalue' (aka 'void () &') cannot have '&' qualifier}}
func_type_rvalue f3; // expected-error{{non-member function of type 'func_type_rvalue' (aka 'void () &&') cannot have '&&' qualifier}}
struct Y {
func_type_lvalue f0;
func_type_rvalue f1;
};
void (X::*mpf1)() & = &X::f0;
void (X::*mpf2)() && = &X::f1;
void (f() &&); // expected-error{{non-member function cannot have '&&' qualifier}}
// FIXME: These are ill-formed.
template<typename T> struct pass {
void f(T);
};
pass<func_type_lvalue> pass0;
pass<func_type_lvalue> pass1;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p9-0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// FIXME: We should catch the case of tag with an incomplete type here (which
// will necessarily be ill-formed as a trailing return type for a function
// definition), and recover with a "type cannot be defined in a trailing return
// type" error.
auto j() -> enum { e3 }; // expected-error{{unnamed enumeration must be a definition}} expected-error {{expected a type}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p13.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -fexceptions -verify %s
// When it is part of a parameter-declaration-clause, the parameter
// pack is a function parameter pack.
template<typename ...Types>
void f0(Types ...args);
template<typename ...Types>
void f1(const Types &...args);
// [ Note: Otherwise, the parameter-declaration is part of a
// template-parameter-list and the parameter pack is a template
// parameter pack; see 14.1. -- end note ]
template<int ...N>
struct X0 { };
template<typename ...Types>
struct X1 {
template<Types ...Values> struct Inner;
};
// A declarator-id or abstract-declarator containing an ellipsis shall
// only be used in a parameter-declaration.
int (...f2)(int); // expected-error{{only function and template parameters can be parameter packs}}
void f3() {
int ...x; // expected-error{{only function and template parameters can be parameter packs}}
if (int ...y = 17) { } // expected-error{{only function and template parameters can be parameter packs}}
for (int ...z = 0; z < 10; ++z) { } // expected-error{{only function and template parameters can be parameter packs}}
try {
} catch (int ...e) { // expected-error{{only function and template parameters can be parameter packs}}
}
}
template<typename ...Types>
struct X2 {
Types ...members; // expected-error{{only function and template parameters can be parameter packs}} \
// expected-error{{data member type contains unexpanded parameter pack}}
};
// The type T of the declarator-id of the function parameter pack
// shall contain a template parameter pack; each template parameter
// pack in T is expanded by the function parameter pack.
template<typename T>
void f4(T ...args); // expected-error{{type 'T' of function parameter pack does not contain any unexpanded parameter packs}}
void f4i(int ... x); // expected-error{{type 'int' of function parameter pack does not contain any unexpanded parameter packs}}
void f4i0(int ...);
namespace array_type {
template<typename T>
void a(T[] ... x); // expected-error{{expected ')'}} expected-note{{to match this '('}}
template<typename T>
void b(T[] ...);
template<typename T>
void c(T ... []); // expected-error{{type 'T []' of function parameter pack does not contain any unexpanded parameter packs}}
template<typename T>
void d(T ... x[]); // expected-error{{type 'T []' of function parameter pack does not contain any unexpanded parameter packs}}
void ai(int[] ... x); // expected-error{{expected ')'}} expected-note{{to match this '('}}
void bi(int[] ...);
void ci(int ... []); // expected-error{{type 'int []' of function parameter pack does not contain any unexpanded parameter packs}}
void di(int ... x[]); // expected-error{{type 'int []' of function parameter pack does not contain any unexpanded parameter packs}}
}
void f5a(auto fp(int)->unk ...) {} // expected-error{{unknown type name 'unk'}}
void f5b(auto fp(int)->auto ...) {} // expected-error{{'auto' not allowed in function return type}}
void f5c(auto fp()->...) {} // expected-error{{expected a type}}
// FIXME: Expand for function and member pointer types.
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void f(int) { } // expected-note {{previous definition is here}}
void f(const int) { } // expected-error {{redefinition of 'f'}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p2-cxx0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
auto a() -> int; // ok
const auto b() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'const auto'}}
auto *c() -> int; // expected-error {{function with trailing return type must specify return type 'auto', not 'auto *'}}
auto (d() -> int); // expected-error {{trailing return type may not be nested within parentheses}}
auto e() -> auto (*)() -> auto (*)() -> void; // ok: same as void (*(*e())())();
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
typedef void F() const;
void f() const; // expected-error {{non-member function cannot have 'const' qualifier}}
F g; // expected-error {{non-member function of type 'F' (aka 'void () const') cannot have 'const' qualifier}}
struct X {
void f() const;
friend void g() const; // expected-error {{non-member function cannot have 'const' qualifier}}
static void h() const; // expected-error {{static member function cannot have 'const' qualifier}}
F i; // ok
friend F j; // expected-error {{non-member function of type 'F' (aka 'void () const') cannot have 'const' qualifier}}
static F k; // expected-error {{static member function of type 'F' (aka 'void () const') cannot have 'const' qualifier}}
};
struct Y {
friend void X::f() const;
friend void ::f() const; // expected-error {{non-member function cannot have 'const' qualifier}}
};
template<typename T> struct S {
typedef T F;
typedef T *P; // expected-error {{pointer to function type 'void () const' cannot have 'const' qualifier}}
typedef T &R; // expected-error {{reference to function type 'void () const' cannot have 'const' qualifier}}
};
S<F> s; // expected-note {{in instantiation of}}
// FIXME: This is ill-formed.
template<typename T> struct U {
void f(T);
};
U<F> u;
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
// FIXME: test with non-std qualifiers
namespace move {
struct Const {
Const(const Const&&) = default; // expected-error {{the parameter for an explicitly-defaulted move constructor may not be const}}
Const& operator=(const Const&&) = default; // expected-error {{the parameter for an explicitly-defaulted move assignment operator may not be const}}
};
struct Volatile {
Volatile(volatile Volatile&&) = default; // expected-error {{the parameter for an explicitly-defaulted move constructor may not be volatile}}
Volatile& operator=(volatile Volatile&&) = default; // expected-error {{the parameter for an explicitly-defaulted move assignment operator may not be volatile}}
};
struct AssignmentRet1 {
AssignmentRet1&& operator=(AssignmentRet1&&) = default; // expected-error {{explicitly-defaulted move assignment operator must return 'move::AssignmentRet1 &'}}
};
struct AssignmentRet2 {
const AssignmentRet2& operator=(AssignmentRet2&&) = default; // expected-error {{explicitly-defaulted move assignment operator must return 'move::AssignmentRet2 &'}}
};
struct ConstAssignment {
ConstAssignment& operator=(ConstAssignment&&) const = default; // expected-error {{an explicitly-defaulted move assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}}
};
}
namespace copy {
struct Volatile {
Volatile(const volatile Volatile&) = default; // expected-error {{the parameter for an explicitly-defaulted copy constructor may not be volatile}}
Volatile& operator=(const volatile Volatile&) = default; // expected-error {{the parameter for an explicitly-defaulted copy assignment operator may not be volatile}}
};
struct Const {
Const(const Const&) = default;
Const& operator=(const Const&) = default;
};
struct NonConst {
NonConst(NonConst&) = default;
NonConst& operator=(NonConst&) = default;
};
struct NonConst2 {
NonConst2(NonConst2&);
NonConst2& operator=(NonConst2&);
};
NonConst2::NonConst2(NonConst2&) = default;
NonConst2 &NonConst2::operator=(NonConst2&) = default;
struct NonConst3 {
NonConst3(NonConst3&) = default;
NonConst3& operator=(NonConst3&) = default;
NonConst nc;
};
struct BadConst {
BadConst(const BadConst&) = default; // expected-error {{is const, but}}
BadConst& operator=(const BadConst&) = default; // expected-error {{is const, but}}
NonConst nc; // makes implicit copy non-const
};
struct AssignmentRet1 {
AssignmentRet1&& operator=(const AssignmentRet1&) = default; // expected-error {{explicitly-defaulted copy assignment operator must return 'copy::AssignmentRet1 &'}}
};
struct AssignmentRet2 {
const AssignmentRet2& operator=(const AssignmentRet2&) = default; // expected-error {{explicitly-defaulted copy assignment operator must return 'copy::AssignmentRet2 &'}}
};
struct ConstAssignment {
ConstAssignment& operator=(const ConstAssignment&) const = default; // expected-error {{an explicitly-defaulted copy assignment operator may not have 'const', 'constexpr' or 'volatile' qualifiers}}
};
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/dcl.fct.def.default/p1.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s
// A function that is explicitly defaulted shall
// [...]
// -- not have default arguments
struct DefArg {
static DefArg &&make();
DefArg(int n = 5) = default; // expected-error {{an explicitly-defaulted constructor cannot have default arguments}}
DefArg(const DefArg &DA = make()) = default; // expected-error {{an explicitly-defaulted constructor cannot have default arguments}}
DefArg(const DefArg &DA, int k = 3) = default; // expected-error {{an explicitly-defaulted copy constructor cannot have default arguments}}
DefArg(DefArg &&DA = make()) = default; // expected-error {{an explicitly-defaulted constructor cannot have default arguments}}
DefArg(DefArg &&DA, int k = 3) = default; // expected-error {{an explicitly-defaulted move constructor cannot have default arguments}}
DefArg &operator=(const DefArg&, int k = 4) = default; // expected-error {{parameter of overloaded 'operator=' cannot have a default argument}}
DefArg &operator=(DefArg&&, int k = 4) = default; // expected-error {{parameter of overloaded 'operator=' cannot have a default argument}}
~DefArg(int k = 5) = default; // expected-error {{destructor cannot have any parameters}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.mptr/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class A {
public:
int& i;
A(int& i) : i(i) { }
static int s;
};
template<typename T> void ft(T& t) {
t.*&T::i = 10; // expected-error{{cannot form a pointer-to-member to member 'i' of reference type 'int &'}}
}
void f() {
int b;
A a(b);
int A::*ip = &A::s; // expected-error {{cannot initialize a variable of type 'int A::*' with an rvalue of type 'int *'}}
a.*&A::s = 10; // expected-error{{right hand operand to .* has non-pointer-to-member type 'int *'}}
a.*&A::i = 10; // expected-error{{cannot form a pointer-to-member to member 'i' of reference type 'int &'}}
ft(a); // expected-note{{in instantiation of function template specialization 'ft<A>' requested here}}
void A::*p = 0; // expected-error{{'p' declared as a member pointer to void}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void h()
{
int i;
extern void h2(int x = sizeof(i)); // expected-error {{default argument references local variable 'i' of enclosing function}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class A {
void f(A* p = this) { } // expected-error{{invalid use of 'this'}}
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p10.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
struct A {
virtual void f(int a = 7); // expected-note{{'A::f' declared here}}
};
struct B : public A {
void f(int a);
};
void m() {
B* pb = new B;
A* pa = pb;
pa->f(); // OK, calls pa->B::f(7)
pb->f(); // expected-error{{too few arguments to function call, expected 1, have 0; did you mean 'A::f'?}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p4.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
void f0(int i, int j, int k = 3);
void f0(int i, int j, int k);
void f0(int i, int j = 2, int k);
void f0(int i, int j, int k);
void f0(int i = 1, // expected-note{{previous definition}}
int j, int k);
void f0(int i, int j, int k); // want 2 decls before next default arg
void f0(int i, int j, int k);
namespace N0 {
void f0(int, int, int); // expected-note{{candidate}}
void test_f0_inner_scope() {
f0(); // expected-error{{no matching}}
}
}
void test_f0_outer_scope() {
f0(); // okay
}
void f0(int i = 1, // expected-error{{redefinition of default argument}}
int, int);
template<typename T> void f1(T); // expected-note{{previous}}
template<typename T>
void f1(T = T()); // expected-error{{cannot be added}}
namespace N1 {
// example from C++03 standard
// FIXME: make these "f2"s into "f"s, then fix our scoping issues
void f2(int, int);
void f2(int, int = 7);
void h() {
f2(3); // OK, calls f(3, 7)
void f(int = 1, int); // expected-error{{missing default argument}}
}
void m()
{
void f(int, int); // expected-note{{'f' declared here}}
f(4); // expected-error{{too few arguments to function call}}
void f(int, int = 5); // expected-note{{previous definition}}
f(4); // okay
void f(int, int = 5); // expected-error{{redefinition of default argument}}
}
void n()
{
f2(6); // okay
}
}
namespace PR18432 {
struct A {
struct B {
static void Foo (int = 0);
};
// should not hide default args
friend void B::Foo (int);
};
void Test ()
{
A::B::Foo ();
}
} // namespace
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p3.cpp
|
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
void nondecl(int (*f)(int x = 5)) // expected-error {{default arguments can only be specified}}
{
void (*f2)(int = 17) // expected-error {{default arguments can only be specified}}
= (void (*)(int = 42))f; // expected-error {{default arguments can only be specified}}
}
struct X0 {
int (*f)(int = 17); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
void (*g())(int = 22); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
void (*h(int = 49))(int);
auto i(int) -> void (*)(int = 9); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
void mem8(int (*fp)(int) = (int (*)(int = 17))0); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
};
template <typename... Ts>
void defaultpack(Ts... = 0) {} // expected-error{{parameter pack cannot have a default argument}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p2.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
void point(int = 3, int = 4);
void test_point() {
point(1,2);
point(1);
point();
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p5.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
float global_f;
void f0(int *ip = &global_f); // expected-error{{cannot initialize}} \
// expected-note{{passing argument to parameter 'ip' here}}
// Example from C++03 standard
int a = 1;
int f(int);
int g(int x = f(a));
void h() {
a = 2;
{
int *a = 0;
g(); // FIXME: check that a is called with a value of 2
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p6.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
class C {
public:
void f(int i = 3); // expected-note{{here}}
void g(int i, int j = 99);
};
void C::f(int i = 3) { } // expected-error{{redefinition of default argument}}
void C::g(int i = 88, int j) { }
void test_C(C c) {
c.f();
c.g();
}
template<typename T>
struct X0 {
void f(int);
struct Inner {
void g(int);
};
};
// DR217
template<typename T>
void X0<T>::f(int = 17) { } // expected-error{{cannot be added}}
// DR217 + DR205 (reading tea leaves)
template<typename T>
void X0<T>::Inner::g(int = 17) { } // expected-error{{cannot be added}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1-cxx0x.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
void f() {
int b[5];
auto a[5] = b; // expected-error{{'a' declared as array of 'auto'}}
auto *c[5] = b; // expected-error{{'c' declared as array of 'auto *'}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p3.cpp
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y -triple x86_64-linux-gnu %s
// If there is a preceding declaration of the entity *in the same scope* in
// which the bound was specified, an omitted array bound is taken to be the
// same as in that earlier declaration
// rdar://13535367
namespace test0 {
extern "C" int array[];
void declare() { extern int array[100]; }
int value1 = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
extern "C" int array[];
int value2 = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
namespace test1 {
extern "C" int array[];
void test() {
{ extern int array[100]; }
extern int array[];
int x = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
}
namespace test2 {
void declare() { extern int array[100]; }
extern int array[];
int value = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
namespace test3 {
void test() {
{ extern int array[100]; }
extern int array[];
int x = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
}
namespace test4 {
extern int array[];
void test() {
extern int array[100];
int x = sizeof(array);
}
int y = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
namespace test5 {
void test() {
extern int array[100];
extern int array[];
int x = sizeof(array);
}
}
namespace test6 {
void test() {
extern int array[100];
{
extern int array[];
int x = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
int y = sizeof(array);
extern int array[];
int z = sizeof(array);
}
}
namespace test7 {
extern int array[100];
void test() {
extern int array[];
int x = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
int y = sizeof(array);
extern int array[];
int z = sizeof(array);
}
namespace test8 {
extern int array[];
void test() {
extern int array[100];
int x = sizeof(array);
}
int y = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
extern int array[];
int z = sizeof(array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}
namespace dependent {
template<typename T> void f() {
extern int arr1[];
extern T arr1;
extern T arr2;
extern int arr2[];
static_assert(sizeof(arr1) == 12, "");
static_assert(sizeof(arr2) == 12, "");
// Use a failing test to ensure the type isn't considered dependent.
static_assert(sizeof(arr2) == 13, ""); // expected-error {{failed}}
}
void g() { f<int[3]>(); } // expected-note {{in instantiation of}}
template<typename T> void h1() {
extern T arr3;
{
int arr3;
{
extern int arr3[];
// Detected in template definition.
(void)sizeof(arr3); // expected-error {{incomplete}}
}
}
}
template<typename T> void h2() {
extern int arr4[3];
{
int arr4;
{
extern T arr4;
// Detected in template instantiation.
(void)sizeof(arr4); // expected-error {{incomplete}}
}
}
}
void i() {
h1<int[3]>();
h2<int[]>(); // expected-note {{in instantiation of}}
}
int arr5[3];
template<typename T> void j() {
extern T arr5;
extern T arr6;
(void)sizeof(arr5); // expected-error {{incomplete}}
(void)sizeof(arr6); // expected-error {{incomplete}}
}
int arr6[3];
void k() { j<int[]>(); } // expected-note {{in instantiation of}}
template<typename T, typename U> void l() {
extern T arrX; // expected-note {{previous}}
extern U arrX; // expected-error {{different type: 'int [4]' vs 'int [3]'}}
(void)sizeof(arrX); // expected-error {{incomplete}}
}
void m() {
l<int[], int[3]>(); // ok
l<int[3], int[]>(); // ok
l<int[3], int[3]>(); // ok
l<int[3], int[4]>(); // expected-note {{in instantiation of}}
l<int[], int[]>(); // expected-note {{in instantiation of}}
}
template<typename T> void n() {
extern T n_var; // expected-error {{redeclaration of 'n_var' with a different type: 'double' vs 'int'}} expected-note {{previous}}
extern T n_fn(); // expected-error {{functions that differ only in their return type cannot be overloaded}} expected-note {{previous}}
}
template void n<int>();
template void n<double>(); // expected-note {{in instantiation of}}
template<typename T> void o() {
extern T o_var; // expected-note {{previous}}
extern T o_fn(); // expected-note {{previous}}
}
template void o<int>();
float o_var; // expected-error {{redefinition of 'o_var' with a different type: 'float' vs 'int'}}
float o_fn(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
int p_var;
int p_fn();
template<typename T> void p() {
extern T p_var;
extern T p_fn();
}
}
namespace use_outside_ns {
namespace A {
extern int a[3];
extern int b[];
extern int c[3];
void f() {
extern int a[];
extern int b[3];
}
template<typename T> void x() {
extern T c;
extern T d;
}
extern int d[3];
template void x<int[]>();
}
int w = sizeof(A::a);
int x = sizeof(A::b); // expected-error {{incomplete}}
int y = sizeof(A::c);
int z = sizeof(A::d);
namespace A {
int g() { return sizeof(a); }
int h() { return sizeof(b); } // expected-error {{incomplete}}
int i() { return sizeof(c); }
int j() { return sizeof(d); }
}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/dcl.decl/dcl.meaning/dcl.array/p1.cpp
|
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
// Simple form
int ar1[10];
// Element type cannot be:
// - (cv) void
volatile void ar2[10]; // expected-error {{incomplete element type 'volatile void'}}
// - a reference
int& ar3[10]; // expected-error {{array of references}}
// - a function type
typedef void Fn();
Fn ar4[10]; // expected-error {{array of functions}}
// - an abstract class
struct Abstract { virtual void fn() = 0; }; // expected-note {{pure virtual}}
Abstract ar5[10]; // expected-error {{abstract class}}
// If we have a size, it must be greater than zero.
int ar6[-1]; // expected-error {{array with a negative size}}
int ar7[0u]; // expected-warning {{zero size arrays are an extension}}
// An array with unknown bound is incomplete.
int ar8[]; // expected-error {{needs an explicit size or an initializer}}
// So is an array with an incomplete element type.
struct Incomplete; // expected-note {{forward declaration}}
Incomplete ar9[10]; // expected-error {{incomplete type}}
// Neither of which should be a problem in situations where no complete type
// is required. (PR5048)
void fun(int p1[], Incomplete p2[10]);
extern int ear1[];
extern Incomplete ear2[10];
// cv migrates to element type
typedef const int cint;
extern cint car1[10];
typedef int intar[10];
// thus this is a valid redeclaration
extern const intar car1;
// Check that instantiation works properly when the element type is a template.
template <typename T> struct S {
typename T::type x; // expected-error {{has no members}}
};
S<int> ar10[10]; // expected-note {{requested here}}
// Ensure that negative array size errors include the name of the declared
// array as this is often used to simulate static_assert with template
// instantiations, placing the 'error message' in the declarator name.
int
user_error_message
[-1]; // expected-error {{user_error_message}}
typedef int
another_user_error_message
[-1]; // expected-error {{another_user_error_message}}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/except
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/except/except.spec/p9-dynamic.cpp
|
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - -fcxx-exceptions -fexceptions | FileCheck %s
void external();
void target() throw(int)
{
// CHECK: invoke void @_Z8externalv()
external();
}
// CHECK: landingpad { i8*, i32 }
// CHECK-NEXT: filter [1 x i8*] [i8* bitcast (i8** @_ZTIi to i8*)]
// CHECK: call void @__cxa_call_unexpected
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/except
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/except/except.spec/p14.cpp
|
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -verify -std=c++11 %s
struct A { };
struct B { };
struct C { };
// Destructor
struct X0 {
virtual ~X0() throw(A); // expected-note{{overridden virtual function is here}}
};
struct X1 {
virtual ~X1() throw(B); // expected-note{{overridden virtual function is here}}
};
struct X2 : public X0, public X1 { }; // expected-error 2{{exception specification of overriding function is more lax than base version}}
// Copy-assignment operator.
struct CA0 {
CA0 &operator=(const CA0&) throw(A);
};
struct CA1 {
CA1 &operator=(const CA1&) throw(B);
};
struct CA2 : CA0, CA1 { };
void test_CA() {
CA2 &(CA2::*captr1)(const CA2&) throw(A, B) = &CA2::operator=;
CA2 &(CA2::*captr2)(const CA2&) throw(A, B, C) = &CA2::operator=;
CA2 &(CA2::*captr3)(const CA2&) throw(A) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}}
CA2 &(CA2::*captr4)(const CA2&) throw(B) = &CA2::operator=; // expected-error{{target exception specification is not superset of source}}
}
// In-class member initializers.
struct IC0 {
int inClassInit = 0;
};
struct IC1 {
int inClassInit = (throw B(), 0);
};
// FIXME: the exception specification on the default constructor is wrong:
// we cannot currently compute the set of thrown types.
static_assert(noexcept(IC0()), "IC0() does not throw");
static_assert(!noexcept(IC1()), "IC1() throws");
namespace PR13381 {
struct NoThrowMove {
NoThrowMove(const NoThrowMove &);
NoThrowMove(NoThrowMove &&) noexcept;
NoThrowMove &operator=(const NoThrowMove &) const;
NoThrowMove &operator=(NoThrowMove &&) const noexcept;
};
struct NoThrowMoveOnly {
NoThrowMoveOnly(NoThrowMoveOnly &&) noexcept;
NoThrowMoveOnly &operator=(NoThrowMoveOnly &&) noexcept;
};
struct X {
const NoThrowMove a;
NoThrowMoveOnly b;
static X val();
static X &ref();
};
// These both perform a move, but that copy might throw, because it calls
// NoThrowMove's copy constructor (because PR13381::a is const).
static_assert(!noexcept(X(X::val())), "");
static_assert(!noexcept(X::ref() = X::val()), "");
}
namespace PR14141 {
// Part of DR1351: the implicit exception-specification is noexcept(false) if
// the set of potential exceptions of the special member function contains
// "any". Hence it is compatible with noexcept(false).
struct ThrowingBase {
ThrowingBase() noexcept(false);
ThrowingBase(const ThrowingBase&) noexcept(false);
ThrowingBase(ThrowingBase&&) noexcept(false);
ThrowingBase &operator=(const ThrowingBase&) noexcept(false);
ThrowingBase &operator=(ThrowingBase&&) noexcept(false);
~ThrowingBase() noexcept(false);
};
struct Derived : ThrowingBase {
Derived() noexcept(false) = default;
Derived(const Derived&) noexcept(false) = default;
Derived(Derived&&) noexcept(false) = default;
Derived &operator=(const Derived&) noexcept(false) = default;
Derived &operator=(Derived&&) noexcept(false) = default;
~Derived() noexcept(false) = default;
};
struct Derived2 : ThrowingBase {
Derived2() = default;
Derived2(const Derived2&) = default;
Derived2(Derived2&&) = default;
Derived2 &operator=(const Derived2&) = default;
Derived2 &operator=(Derived2&&) = default;
~Derived2() = default;
};
struct Derived3 : ThrowingBase {
Derived3() noexcept(true) = default; // expected-error {{does not match the calculated}}
Derived3(const Derived3&) noexcept(true) = default; // expected-error {{does not match the calculated}}
Derived3(Derived3&&) noexcept(true) = default; // expected-error {{does not match the calculated}}
Derived3 &operator=(const Derived3&) noexcept(true) = default; // expected-error {{does not match the calculated}}
Derived3 &operator=(Derived3&&) noexcept(true) = default; // expected-error {{does not match the calculated}}
~Derived3() noexcept(true) = default; // expected-error {{does not match the calculated}}
};
}
namespace rdar13017229 {
struct Base {
virtual ~Base() {}
};
struct Derived : Base {
virtual ~Derived();
Typo foo(); // expected-error{{unknown type name 'Typo'}}
};
}
namespace InhCtor {
template<int> struct X {};
struct Base {
Base(X<0>) noexcept(true);
Base(X<1>) noexcept(false);
Base(X<2>) throw(X<2>);
template<typename T> Base(T) throw(T);
};
template<typename T> struct Throw {
Throw() throw(T);
};
struct Derived : Base, Throw<X<3>> {
using Base::Base;
Throw<X<4>> x;
};
struct Test {
friend Derived::Derived(X<0>) throw(X<3>, X<4>);
friend Derived::Derived(X<1>) noexcept(false);
friend Derived::Derived(X<2>) throw(X<2>, X<3>, X<4>);
};
static_assert(!noexcept(Derived{X<5>{}}), "");
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/except
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/except/except.spec/p5-delayed.cpp
|
// RUN: %clang_cc1 -std=c++11 -verify %s -fexceptions -fcxx-exceptions
struct A { struct X { virtual ~X() throw(Y); }; struct Y : X {}; };
struct B { struct X { virtual void f() throw(Y); }; struct Y : X { void f() throw(Y); }; };
struct C { struct X { virtual void f() throw(Y); }; struct Y : X { void f() throw(); }; };
struct D { struct X { virtual void f() throw(Y); }; struct Y : X { void f() noexcept; }; };
struct E { struct Y; struct X { virtual Y &operator=(const Y&) throw(Y); }; struct Y : X {}; };
struct F {
struct X {
virtual void f() throw(Y); // expected-note {{here}}
};
struct Y : X {
void f() throw(int); // expected-error {{more lax}}
};
};
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/except
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/except/except.spec/p5-pointers.cpp
|
// RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
// Assignment of function pointers.
struct A
{
};
struct B1 : A
{
};
struct B2 : A
{
};
struct D : B1, B2
{
};
struct P : private A
{
};
// Some functions to play with below.
void s1() throw();
void s2() throw(int);
void s3() throw(A);
void s4() throw(B1);
void s5() throw(D);
void s6();
void s7() throw(int, float);
void (*s8())() throw(B1); // s8 returns a pointer to function with spec
void s9(void (*)() throw(B1)); // s9 takes pointer to function with spec
void s10() noexcept;
void s11() noexcept(true);
void s12() noexcept(false);
void fnptrs()
{
// Assignment and initialization of function pointers.
void (*t1)() throw() = &s1; // valid
t1 = &s2; // expected-error {{not superset}} expected-error {{incompatible type}}
t1 = &s3; // expected-error {{not superset}} expected-error {{incompatible type}}
void (&t2)() throw() = s2; // expected-error {{not superset}}
void (*t3)() throw(int) = &s2; // valid
void (*t4)() throw(A) = &s1; // valid
t4 = &s3; // valid
t4 = &s4; // valid
t4 = &s5; // expected-error {{not superset}} expected-error {{incompatible type}}
void (*t5)() = &s1; // valid
t5 = &s2; // valid
t5 = &s6; // valid
t5 = &s7; // valid
t1 = t3; // expected-error {{not superset}} expected-error {{incompatible type}}
t3 = t1; // valid
void (*t6)() throw(B1);
t6 = t4; // expected-error {{not superset}} expected-error {{incompatible type}}
t4 = t6; // valid
t5 = t1; // valid
t1 = t5; // expected-error {{not superset}} expected-error {{incompatible type}}
// return types and arguments must match exactly, no inheritance allowed
void (*(*t7)())() throw(B1) = &s8; // valid
void (*(*t8)())() throw(A) = &s8; // expected-error {{return types differ}}
void (*(*t9)())() throw(D) = &s8; // expected-error {{return types differ}}
void (*t10)(void (*)() throw(B1)) = &s9; // valid
void (*t11)(void (*)() throw(A)) = &s9; // expected-error {{argument types differ}}
void (*t12)(void (*)() throw(D)) = &s9; // expected-error {{argument types differ}}
}
// Member function stuff
struct Str1 { void f() throw(int); }; // expected-note {{previous declaration}}
void Str1::f() // expected-warning {{missing exception specification}}
{
}
void mfnptr()
{
void (Str1::*pfn1)() throw(int) = &Str1::f; // valid
void (Str1::*pfn2)() = &Str1::f; // valid
void (Str1::*pfn3)() throw() = &Str1::f; // expected-error {{not superset}}
}
|
0 |
repos/DirectXShaderCompiler/tools/clang/test/CXX/except
|
repos/DirectXShaderCompiler/tools/clang/test/CXX/except/except.spec/p4.cpp
|
// RUN: %clang_cc1 -std=c++11 %s -verify -fcxx-exceptions
// We permit overriding an implicit exception specification with an explicit one
// as an extension, for compatibility with existing code.
struct S {
void a(); // expected-note {{here}}
~S(); // expected-note {{here}}
void operator delete(void*); // expected-note {{here}}
};
void S::a() noexcept {} // expected-error {{does not match previous}}
S::~S() noexcept {} // expected-warning {{function previously declared with an implicit exception specification redeclared with an explicit exception specification}}
void S::operator delete(void*) noexcept {} // expected-warning {{function previously declared with an implicit exception specification redeclared with an explicit exception specification}}
struct T {
void a() noexcept; // expected-note {{here}}
~T() noexcept; // expected-note {{here}}
void operator delete(void*) noexcept; // expected-note {{here}}
};
void T::a() {} // expected-warning {{missing exception specification 'noexcept'}}
T::~T() {} // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}
void T::operator delete(void*) {} // expected-warning {{function previously declared with an explicit exception specification redeclared with an implicit exception specification}}
// The extension does not extend to function templates.
template<typename T> struct U {
T t;
~U(); // expected-note {{here}}
void operator delete(void*); // expected-note {{here}}
};
template<typename T> U<T>::~U() noexcept(true) {} // expected-error {{exception specification in declaration does not match previous declaration}}
template<typename T> void U<T>::operator delete(void*) noexcept(false) {} // expected-error {{exception specification in declaration does not match previous declaration}}
// Make sure this restriction interacts properly with __attribute__((noreturn))
void __attribute__ ((__noreturn__)) PR17110(int status) throw();
void PR17110(int status) throw();
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.