1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -verify -fsyntax-only -pedantic 2*f4a2713aSLionel Sambuc 3*f4a2713aSLionel Sambuc // This file tests the clang extension which allows initializing the components 4*f4a2713aSLionel Sambuc // of a complex number individually using an initialization list. Basically, 5*f4a2713aSLionel Sambuc // if you have an explicit init list for a complex number that contains two 6*f4a2713aSLionel Sambuc // initializers, this extension kicks in to turn it into component-wise 7*f4a2713aSLionel Sambuc // initialization. 8*f4a2713aSLionel Sambuc // 9*f4a2713aSLionel Sambuc // This extension is useful because there isn't any way to accurately build 10*f4a2713aSLionel Sambuc // a complex number at the moment besides setting the components with 11*f4a2713aSLionel Sambuc // __real__ and __imag__, which is inconvenient and not usable for constants. 12*f4a2713aSLionel Sambuc // (Of course, there are other extensions we could implement that would 13*f4a2713aSLionel Sambuc // allow this, like some sort of __builtin_build_complex.) 14*f4a2713aSLionel Sambuc // 15*f4a2713aSLionel Sambuc // FIXME: It would be a good idea to have a warnings for implicit 16*f4a2713aSLionel Sambuc // real->complex and complex->real conversions; as-is, it's way too easy 17*f4a2713aSLionel Sambuc // to get implicit conversions when they are not intended. 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc // Basic testcase 20*f4a2713aSLionel Sambuc _Complex float valid1 = { 1.0f, 2.0f }; // expected-warning {{specifying real and imaginary components is an extension}} 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc 23*f4a2713aSLionel Sambuc // Struct for nesting tests 24*f4a2713aSLionel Sambuc struct teststruct { _Complex float x; }; 25*f4a2713aSLionel Sambuc 26*f4a2713aSLionel Sambuc 27*f4a2713aSLionel Sambuc // Random other valid stuff 28*f4a2713aSLionel Sambuc _Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} expected-warning {{specifying real and imaginary components is an extension}} 29*f4a2713aSLionel Sambuc struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying real and imaginary components is an extension}} 30*f4a2713aSLionel Sambuc _Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}} 31*f4a2713aSLionel Sambuc // FIXME: We need some sort of warning for valid5 32*f4a2713aSLionel Sambuc _Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary constants}} expected-warning {{specifying real and imaginary components is an extension}} 33*f4a2713aSLionel Sambuc 34*f4a2713aSLionel Sambuc 35*f4a2713aSLionel Sambuc // Random invalid stuff 36*f4a2713aSLionel Sambuc struct teststruct invalid1 = { 1, 2 }; // expected-warning {{excess elements}} 37*f4a2713aSLionel Sambuc _Complex float invalid2 = { 1, 2, 3 }; // expected-warning {{excess elements}} 38*f4a2713aSLionel Sambuc _Complex float invalid3 = {}; // expected-error {{scalar initializer cannot be empty}} expected-warning {{GNU empty initializer}} 39*f4a2713aSLionel Sambuc 40*f4a2713aSLionel Sambuc 41*f4a2713aSLionel Sambuc // Check incomplete array sizing 42*f4a2713aSLionel Sambuc _Complex float sizetest1[] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 2 {{specifying real and imaginary components is an extension}} 43*f4a2713aSLionel Sambuc _Complex float sizecheck1[(sizeof(sizetest1) == sizeof(*sizetest1)*2) ? 1 : -1]; 44*f4a2713aSLionel Sambuc _Complex float sizetest2[] = { 1.0f, 1.0f, {1.0f, 1.0f} }; // expected-warning {{specifying real and imaginary components is an extension}} 45*f4a2713aSLionel Sambuc _Complex float sizecheck2[(sizeof(sizetest2) == sizeof(*sizetest2)*3) ? 1 : -1]; 46*f4a2713aSLionel Sambuc 47*f4a2713aSLionel Sambuc // Constant-folding with init list. 48*f4a2713aSLionel Sambuc _Complex float x = 2 + (_Complex float) { 1, 2 }; // expected-warning {{specifying real and imaginary components is an extension}} 49