Skip to content

Commit 3debf14

Browse files
committed
Ensure __LINE__ is expanded
We previously generated several declarations with the same name, because the C preprocessor does not expand __LINE__ after a concatenation operator. Add two levels of indirection to achieve this. Using declarations with the same name was kind of ok for the C front-end, but is a bug with any C++ front-end.
1 parent 01255db commit 3debf14

File tree

47 files changed

+229
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+229
-89
lines changed

regression/ansi-c/Struct_Bitfields1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
struct S1
58
{

regression/ansi-c/Struct_Enum_Padding1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
#include <inttypes.h>
44

5-
#define STATIC_ASSERT(condition) \
6-
int some_array##__LINE__[(condition) ? 1 : -1]
5+
# define CONCAT(a, b) a##b
6+
# define CONCAT2(a, b) CONCAT(a, b)
7+
8+
# define STATIC_ASSERT(condition) \
9+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
710

811
// Debian package openvswitch
912
enum __attribute__((__packed__)) ofpact_type {

regression/ansi-c/Struct_Initialization1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
struct A {
58
int x;

regression/ansi-c/Struct_Initialization2/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
struct A {
58
int x;

regression/ansi-c/Struct_Padding2/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
enum {
58
RTAX_UNSPEC,

regression/ansi-c/Struct_Padding3/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifndef __GNUC__
58
#define __builtin_offsetof(a, b) ((unsigned long long)&(((a *)0)->b))

regression/ansi-c/Struct_Padding4/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
struct Z1
58
{

regression/ansi-c/Struct_Padding5/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef _MSC_VER
58

regression/ansi-c/Struct_Padding6/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#pragma pack(4)
58

regression/ansi-c/Union_Padding1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef _MSC_VER
58

regression/ansi-c/Universal_characters1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
int identifier_\u0201_;
22
int \u0201_abc;
33

4-
#define STATIC_ASSERT(condition) \
5-
int some_array##__LINE__[(condition) ? 1 : -1];
4+
#define CONCAT(a, b) a##b
5+
#define CONCAT2(a, b) CONCAT(a, b)
6+
7+
#define STATIC_ASSERT(condition) \
8+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
69

710
char my_string[]="\u0201";
811
STATIC_ASSERT(sizeof(my_string)==3);

regression/ansi-c/_Alignof1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
// C11: _Alignof
58
// 6.5.3.4

regression/ansi-c/_Bool1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
// C11:
58
// 6.3.1.2 Boolean type

regression/ansi-c/_Generic1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#define G(X) _Generic((X), \
58
long double: 1, \

regression/ansi-c/array_initialization1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
// 6.7.9, 14: An array of character type may be initialized by a character
58
// string literal or UTF−8 string literal, optionally enclosed in braces.

regression/ansi-c/array_initialization3/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT_sizeof(condition) \
2-
int[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
int A[];
58
int B[];

regression/ansi-c/bitfields1/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <limits.h>
22

3-
#define STATIC_ASSERT(condition) int some_array##__LINE__[(condition) ? 1 : -1]
3+
#define CONCAT(a, b) a##b
4+
#define CONCAT2(a, b) CONCAT(a, b)
5+
6+
#define STATIC_ASSERT(condition) \
7+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
48

59
#if CHAR_BIT == 8
610
struct bits

regression/ansi-c/character_literals1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
// character literals such as are of type int in C
58
STATIC_ASSERT(sizeof('a')==sizeof(int));

regression/ansi-c/cprover_bool1/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#define STATIC_ASSERT(condition) int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
26

37
struct bits
48
{

regression/ansi-c/enum3/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#if defined(__GNUC__)
58

regression/ansi-c/float_constant1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
// hex-based constants
58
STATIC_ASSERT(0x1.0p-95f == 2.524355e-29f);

regression/ansi-c/gcc_attributes10/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int array##__LINE__[(condition) ? 1 : -1]
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef __GNUC__
58
#ifndef __clang__

regression/ansi-c/gcc_attributes3/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef __GNUC__
58

regression/ansi-c/gcc_attributes4/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef __GNUC__
58

regression/ansi-c/gcc_attributes5/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef __GNUC__
58

regression/ansi-c/gcc_attributes6/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef __GNUC__
58

regression/ansi-c/gcc_attributes8/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
#ifdef __GNUC__
58

regression/ansi-c/gcc_builtins2/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ extern double cabs (double _Complex __z);
88
extern double fabs (double __x);
99
extern long double cabsl (long double _Complex __z);
1010

11-
#define STATIC_ASSERT(a) int __dummy__[(a)?1:-1]
11+
# define CONCAT(a, b) a##b
12+
# define CONCAT2(a, b) CONCAT(a, b)
13+
14+
# define STATIC_ASSERT(condition) \
15+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
1216
#endif
1317

1418
int main()

regression/ansi-c/gcc_builtins4/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifdef __GNUC__
22

3-
#define STATIC_ASSERT(a) int __dummy__[(a)?1:-1]
3+
# define CONCAT(a, b) a##b
4+
# define CONCAT2(a, b) CONCAT(a, b)
5+
6+
# define STATIC_ASSERT(condition) \
7+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
48

59
struct { int i; _Bool bit_field : 1; } s;
610
union { int i; } u;

regression/ansi-c/gcc_builtins5/main.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ struct pthread
1717
};
1818
};
1919

20-
#define STATIC_ASSERT(a) int __dummy__[(a)?1:-1]
20+
# define CONCAT(a, b) a##b
21+
# define CONCAT2(a, b) CONCAT(a, b)
22+
23+
# define STATIC_ASSERT(condition) \
24+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
2125

2226
int main()
2327
{

regression/ansi-c/gcc_types_compatible_p1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
int i;
58
double d;

regression/ansi-c/gcc_types_compatible_p2/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#ifdef __GNUC__
22

3-
#define STATIC_ASSERT(condition) \
4-
int some_array##__LINE__[(condition) ? 1 : -1]
3+
# define CONCAT(a, b) a##b
4+
# define CONCAT2(a, b) CONCAT(a, b)
5+
6+
# define STATIC_ASSERT(condition) \
7+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
58

69
int getopt_long(int i, char * const* s);
710
int getopt_long_nn(int, char * const*);

regression/ansi-c/gcc_types_compatible_p3/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#ifdef __GNUC__
22

3-
#define STATIC_ASSERT(condition) \
4-
int some_array##__LINE__[(condition) ? 1 : -1]
3+
# define CONCAT(a, b) a##b
4+
# define CONCAT2(a, b) CONCAT(a, b)
5+
6+
# define STATIC_ASSERT(condition) \
7+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
58

69
// Debian package linux-tools
710
enum help_format {

regression/ansi-c/gcc_types_compatible_p4/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
typedef struct struct_tag
58
{

regression/ansi-c/integer_constant1/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#define STATIC_ASSERT(condition) \
2-
int some_array##__LINE__[(condition) ? 1 : -1];
1+
#define CONCAT(a, b) a##b
2+
#define CONCAT2(a, b) CONCAT(a, b)
3+
4+
#define STATIC_ASSERT(condition) \
5+
int CONCAT2(some_array, __LINE__)[(condition) ? 1 : -1]
36

47
STATIC_ASSERT('\''==39);
58
STATIC_ASSERT(L'\''==39);

0 commit comments

Comments
 (0)