brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.8 KiB · 0f67470 Raw
302 lines · c
1/* RUN: %clang_cc1 -std=c89 -fsyntax-only -Wvla -verify=expected,c89only,c17andearlier -pedantic -Wno-c11-extensions %s2   RUN: %clang_cc1 -std=c99 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic -Wno-c11-extensions %s3   RUN: %clang_cc1 -std=c11 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s4   RUN: %clang_cc1 -std=c17 -fsyntax-only -Wvla -verify=expected,c99andup,c17andearlier -pedantic %s5   RUN: %clang_cc1 -std=c2x -fsyntax-only -Wvla -verify=expected,c99andup,c23andup -pedantic %s6 */7 8/* The following are DRs which do not require tests to demonstrate9 * conformance or nonconformance.10 *11 * WG14 DR300: yes12 * Translation-time expresssion evaluation13 *14 * WG14 DR301: yes15 * Meaning of FE_* macros in <fenv.h>16 *17 * WG14 DR303: yes18 * Breaking up the very long sentence describing preprocessing directive19 *20 * WG14 DR307: yes21 * Clarifiying arguments vs. parameters22 *23 * WG14 DR308: yes24 * Clarify that source files et al. need not be "files"25 *26 * WG14 DR310: yes27 * Add non-corner case example of trigraphs28 *29 * WG14 DR312: yes30 * Meaning of "known constant size"31 *32 * WG14 DR333: yes33 * Missing Predefined Macro Name34 *35 * WG14 DR342: dup 34036 * VLAs and conditional expressions37 */38 39 40/* WG14 DR302: yes41 * Adding underscore to portable include file name character set42 */43#include "./abc_123.h"44#ifndef WE_SUPPORT_DR30245#error "Oh no, we don't support DR302 after all!"46#endif47 48/* WG14 DR304: yes49 * Clarifying illegal tokens in #if directives50 */51/* expected-error@+3 {{invalid token at start of a preprocessor expression}}52   expected-warning@+3 {{missing terminating ' character}}53 */54#if 'test55#endif56 57/* WG14 DR305: yes58 * Clarifying handling of keywords in #if directives59 */60#if int61#error "We definitely should not have gotten here"62#endif63 64/* WG14 DR306: yes65 * Clarifying that rescanning applies to object-like macros66 */67#define REPLACE 168#define THIS REPLACE69#if THIS != 170#error "We definitely should not have gotten here"71#endif72 73/* WG14 DR311: yes74 * Definition of variably modified types75 */76void dr311(int x) {77  typedef int vla[x]; /* expected-warning {{variable length array}} */78 79  /* Ensure that a constant array of variable-length arrays are still80   * considered a variable-length array.81   */82  vla y[3]; /* expected-warning {{variable length array}} */83}84 85/* WG14 DR313: yes86 * Incomplete arrays of VLAs87 */88void dr313(int i) {89  int c[][i] = { 0 }; /* expected-error {{variable-sized object may not be initialized}}90                         expected-warning {{variable length array}}91                       */92}93 94/* WG14 DR315: yes95 * Implementation-defined bit-field types96 */97struct dr315_t {98  unsigned long long a : 37; /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */99  unsigned long long b : 37; /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */100 101  short c : 8;102  short d : 8;103} dr315;104_Static_assert(sizeof(dr315.a + dr315.b) == sizeof(unsigned long long), ""); /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */105/* Demonstrate that integer promotions still happen when less than the width of106 * an int.107 */108_Static_assert(sizeof(dr315.c + dr315.d) == sizeof(int), "");109 110#if __STDC_VERSION__ < 202311L111/* WG14 DR316: yes112 * Unprototyped function types113 */114void dr316_1(a) int a; {}  /* expected-warning {{a function definition without a prototype is deprecated in all versions of C and is not supported in C23}} */115void (*dr316_1_ptr)(int, int, int) = dr316_1;116 117/* WG14 DR317: yes118 * Function definitions with empty parentheses119 *120 * Despite the function with empty parens being a definition, this does not121 * provide a prototype for the function. However, calling the function with122 * arguments is undefined behavior, so it is defensible for us to warn the user123 * about it. They key point to this DR is that we give the "without a124 * prototype" warnings to demonstrate we don't give this function a prototype.125 */126void dr317_1() {}  /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */127void dr317_2(void) {128  if (0)129    dr317_1(1); /* expected-warning {{too many arguments in call to 'dr317_1'}}130                   expected-warning {{passing arguments to 'dr317_1' without a prototype is deprecated in all versions of C and is not supported in C23}}131                 */132}133#endif /* __STDC_VERSION__ < 202311L */134 135/* WG14 DR320: yes136 * Scope of variably modified type137 */138int dr320_v;139typedef int dr320_t[dr320_v]; /* c89only-warning {{variable length arrays are a C99 feature}}140                                 expected-error {{variable length array declaration not allowed at file scope}}141                                 c99andup-warning {{variable length array used}}142                               */143void dr320(int okay[dr320_v]) { /* c89only-warning {{variable length arrays are a C99 feature}}144                                   c99andup-warning {{variable length array used}}145                                 */146  typedef int type[dr320_v]; /* c89only-warning {{variable length arrays are a C99 feature}}147                                c99andup-warning {{variable length array used}}148                              */149  extern type bad;  /* expected-error {{variable length array declaration cannot have 'extern' linkage}} */150 151  /* C99 6.7.5.2p2, second sentence. */152  static type fine; /* expected-error {{variable length array declaration cannot have 'static' storage duration}} */153}154 155/* WG14 DR321: yes156 * Wide character code values for members of the basic character set157 */158#define DR321 (\159    ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' &&           \160    '\n' == L'\n' &&                                                            \161    'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' &&  \162    'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' &&  \163    'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' &&  \164    'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' &&  \165    'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' &&  \166    'z' == L'z' &&                                                              \167    'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' &&  \168    'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' &&  \169    'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' &&  \170    'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' &&  \171    'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' &&  \172    'Z' == L'Z' &&                                                              \173    '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' &&  \174    '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' &&                 \175    '9' == L'9' &&                                                              \176    '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' &&  \177    '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' &&  \178    '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' &&  \179    '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' &&  \180    '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' &&  \181    ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\''                \182  )183#if __STDC_MB_MIGHT_NEQ_WC__184#ifndef __FreeBSD__ /* PR22208, FreeBSD expects us to give a bad (but conforming) answer here. */185_Static_assert(!DR321, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation");186#endif187#else188_Static_assert(DR321, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs");189#endif190 191/* WG14 DR328: partial192 * String literals in compound literal initialization193 *194 * DR328 is implemented properly in terms of allowing string literals, but is195 * not implemented. See DR339 (marked as a duplicate of this one) for details.196 */197const char *dr328_v = (const char *){"this is a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */198void dr328(void) {199  const char *val = (const char *){"also a string literal"}; /* c89only-warning {{compound literals are a C99-specific feature}} */200}201 202/* WG14 DR335: yes203 * _Bool bit-fields204 *205 * See dr335.c also, which tests the runtime behavior of the part of the DR206 * which will compile.207 */208void dr335(void) {209  struct bits_ {210    _Bool bbf3 : 3; /* expected-error {{width of bit-field 'bbf3' (3 bits) exceeds the width of its type (1 bit)}}211                       c89only-warning {{'_Bool' is a C99 extension}}212                     */213  };214}215 216/* WG14 DR339: dup 328217 * Variably modified compound literals218 *219 * This DR is marked as a duplicate of DR328, see that DR for further220 * details.221 *222 * FIXME: we should be diagnosing this compound literal as creating a variably-223 * modified type at file scope, as we would do for a file scope variable.224 */225extern int dr339_v;226void *dr339 = &(int (*)[dr339_v]){ 0 }; /* c89only-warning {{variable length arrays are a C99 feature}}227                                           c99andup-warning {{variable length array used}}228                                           c89only-warning {{compound literals are a C99-specific feature}}229                                         */230 231/* WG14 DR340: yes232 * Composite types for variable-length arrays233 *234 * The DR made this behavior undefined because implementations disagreed on the235 * behavior. For this DR, Clang accepts the code and GCC rejects it. It's236 * unclear whether the Clang behavior is intentional, but because the code is237 * UB, any behavior is acceptable.238 */239#if __STDC_VERSION__ < 202311L240void dr340(int x, int y) {241  typedef void (*T1)(int);242  typedef void (*T2)(); /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */243 244  T1 (*a)[] = 0;245  T2 (*b)[x] = 0;       /* c89only-warning {{variable length arrays are a C99 feature}}246                           c99andup-warning {{variable length array used}}247                         */248  (y ? a : b)[0][0]();249}250#endif /* __STDC_VERSION__ < 202311L */251 252/* WG14 DR341: yes253 * [*] in abstract declarators254 */255void dr341_1(int (*)[*]);                  /* c89only-warning {{variable length arrays are a C99 feature}}256                                              c99andup-warning {{variable length array used}}257                                            */258void dr341_2(int (*)[sizeof(int (*)[*])]); /* expected-error {{star modifier used outside of function prototype}} */259 260/* WG14 DR343: yes261 * Initializing qualified wchar_t arrays262 */263void dr343(void) {264  const __WCHAR_TYPE__ x[] = L"foo";265}266 267/* WG14 DR344: yes268 * Casts in preprocessor conditional expressions269 *270 * Note: this DR removed a constraint about not containing casts because there271 * are no keywords, therefore no types to cast to, so casts simply don't exist272 * as a construct during preprocessing.273 */274#if (int)+0275#error "this should not be an error, we shouldn't get here"276#else277/* expected-error@+1 {{"reached"}} */278#error "reached"279#endif280 281/* WG14 DR345: yes282 * Where does parameter scope start?283 */284void f(long double f,285       char (**a)[10 * sizeof f]) {286  _Static_assert(sizeof **a == sizeof(long double) * 10, "");287}288 289/* WG14 DR309: yes290 * Clarifying trigraph substitution291 */292int dr309??(1??) = { 1 }; /* c17andearlier-warning {{trigraph converted to '[' character}}293                             c17andearlier-warning {{trigraph converted to ']' character}}294                             c23andup-warning 2 {{trigraph ignored}}295                             c23andup-error {{expected ';' after top level declarator}}296                           */297 298/* NOTE: Due to interactions with the diagnostic system, dr309 should be the299 * last test case in this file because subsequent diagnostics may not be300 * generated as expected.301 */302