76 lines · c
1// RUN: %clang_cc1 -verify -std=c99 %s2// RUN: %clang_cc1 -verify -std=c99 -fno-dollars-in-identifiers %s3 4/* WG14 N717: Clang 175 * Extended identifiers6 */7 8// Used as a sink for UCNs.9#define M(arg)10 11// C99 6.4.3p1 specifies the grammar for UCNs. A \u must be followed by exactly12// four hex digits, and \U must be followed by exactly eight.13M(\u1) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}14M(\u12) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}15M(\u123) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}16M(\u1234) // Okay17M(\u12345)// Okay, two tokens (UCN followed by 5)18 19M(\U1) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}20M(\U12) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}21M(\U123) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}22M(\U1234) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} \23 expected-note {{did you mean to use '\u'?}}24M(\U12345) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}25M(\U123456) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}26M(\U1234567) // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}}27M(\U12345678) // Okay28M(\U123456789) // Okay-ish, two tokens (valid-per-spec-but-actually-invalid UCN followed by 9)29 30// Now test the ones that should work. Note, these work in C17 and earlier but31// are part of the basic character set in C23 and thus should be diagnosed in32// that mode. They're valid in a character constant, but not valid in an33// identifier, except for U+0024 which is allowed if -fdollars-in-identifiers34// is enabled.35// FIXME: These three should be handled the same way, and should be accepted36// when dollar signs are allowed in identifiers, rather than rejected, see37// GH87106.38M(\u0024) // expected-error {{character '$' cannot be specified by a universal character name}}39M(\U00000024) // expected-error {{character '$' cannot be specified by a universal character name}}40M($)41 42// These should always be rejected because they're not valid identifier43// characters.44// FIXME: the diagnostic could be improved to make it clear this is an issue45// with forming an identifier rather than a UCN.46M(\u0040) // expected-error {{character '@' cannot be specified by a universal character name}}47M(\u0060) // expected-error {{character '`' cannot be specified by a universal character name}}48M(\U00000040) // expected-error {{character '@' cannot be specified by a universal character name}}49M(\U00000060) // expected-error {{character '`' cannot be specified by a universal character name}}50 51// UCNs outside of identifiers are handled in Phase 5 of translation, so we52// cannot use the macro expansion to test their behavior.53 54// This is outside of the range of values specified by ISO 10646.55const char *c1 = "\U00110000"; // expected-error {{invalid universal character}}56// This does not fall outside of the range57const char *c2 = "\U0010FFFF";58 59// These should always be accepted because they're a valid in a character60// constant.61int c3 = '\u0024';62int c4 = '\u0040';63int c5 = '\u0060';64 65int c6 = '\U00000024';66int c7 = '\U00000040';67int c8 = '\U00000060';68 69// Valid lone surrogates.70M(\uD799)71const char *c9 = "\U0000E000";72 73// Invalid lone surrogates, which are excluded explicitly by 6.4.3p2.74M(\uD800) // expected-error {{invalid universal character}}75const char *c10 = "\U0000DFFF"; // expected-error {{invalid universal character}}76