(root)/
gcc-13.2.0/
gcc/
testsuite/
c-c++-common/
attributes-4.c
       1  /* PR c/88363 - alloc_align attribute doesn't accept enumerated arguments
       2     Verify that attribute positional arguments can refer to all C integer
       3     types except _Bool in both C and C++.
       4     { dg-do compile }
       5     { dg-options "-Wall" }
       6     { dg-options "-Wall -Wno-c++-compat" { target c } } */
       7  
       8  #define ATTR(...) __attribute__ ((__VA_ARGS__))
       9  
      10  #if __cplusplus == 199711L
      11  typedef __CHAR16_TYPE__ char16_t;
      12  typedef __CHAR32_TYPE__ char32_t;
      13  #elif !__cplusplus
      14  typedef _Bool           bool;
      15  typedef __CHAR16_TYPE__ char16_t;
      16  typedef __CHAR32_TYPE__ char32_t;
      17  typedef __WCHAR_TYPE__  wchar_t;
      18  #endif
      19  
      20  enum A { A0 };
      21  
      22  ATTR (alloc_align (1)) void* falloc_align_char (char);
      23  ATTR (alloc_align (1)) void* falloc_align_char16 (char16_t);
      24  ATTR (alloc_align (1)) void* falloc_align_char32 (char32_t);
      25  ATTR (alloc_align (1)) void* falloc_align_wchar (wchar_t);
      26  /* Using an enum might make sense in an API that limits the alignments
      27     it accepts to just the set of the defined enumerators.   */
      28  ATTR (alloc_align (1)) void* falloc_align_enum (enum A);
      29  #ifdef __SIZEOF_INT128__
      30  ATTR (alloc_align (1)) void* falloc_align_int128 (__int128_t);
      31  #endif
      32  
      33  
      34  ATTR (alloc_align (1)) void* falloc_size_char (char);
      35  ATTR (alloc_size (1)) void* falloc_size_char16 (char16_t);
      36  ATTR (alloc_size (1)) void* falloc_size_char32 (char32_t);
      37  ATTR (alloc_size (1)) void* falloc_size_wchar (wchar_t);
      38  ATTR (alloc_size (1)) void* falloc_size_enum (enum A);
      39  #ifdef __SIZEOF_INT128__
      40  ATTR (alloc_align (1)) void* falloc_size_int128 (__int128_t);
      41  #endif
      42  
      43  
      44  typedef struct { int i; } S;
      45  
      46  /* Using bool is most likely a bug and so diagnosed even though
      47     it could be accepted.  None of the other types makes sense.  */
      48  ATTR (alloc_align (1)) void* falloc_align_bool (bool);      /* { dg-warning "attribute argument value .1. refers to parameter type .\(_Bool|bool\)" } */
      49  ATTR (alloc_align (1)) void* falloc_align_float (float);    /* { dg-warning "attribute argument value .1. refers to parameter type .float" } */
      50  ATTR (alloc_align (1)) void* falloc_align_voidp (void*);    /* { dg-warning "attribute argument value .1. refers to parameter type .void ?\\\*" } */
      51  ATTR (alloc_align (1)) void* falloc_align_struct (S);       /* { dg-warning "attribute argument value .1. refers to parameter type .S" } */