mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-28 03:46:06 +00:00

C89 had a questionable feature where the compiler would implicitly declare a function that the user called but was never previously declared. The resulting function would be globally declared as extern int func(); -- a function without a prototype which accepts zero or more arguments. C99 removed support for this questionable feature due to severe security concerns. However, there was no deprecation period; C89 had the feature, C99 didn't. So Clang (and GCC) both supported the functionality as an extension in C99 and later modes. C2x no longer supports that function signature as it now requires all functions to have a prototype, and given the known security issues with the feature, continuing to support it as an extension is not tenable. This patch changes the diagnostic behavior for the -Wimplicit-function-declaration warning group depending on the language mode in effect. We continue to warn by default in C89 mode (due to the feature being dangerous to use). However, because this feature will not be supported in C2x mode, we've diagnosed it as being invalid for so long, the security concerns with the feature, and the trivial workaround for users (declare the function), we now default the extension warning to an error in C99-C17 mode. This still gives users an easy workaround if they are extensively using the extension in those modes (they can disable the warning or use -Wno-error to downgrade the error), but the new diagnostic makes it more clear that this feature is not supported and should be avoided. In C2x mode, we no longer allow an implicit function to be defined and treat the situation the same as any other lookup failure. Differential Revision: https://reviews.llvm.org/D122983
89 lines
3.3 KiB
C
89 lines
3.3 KiB
C
// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c11 -Wno-unused-value
|
|
|
|
enum e0; // expected-note{{forward declaration of 'enum e0'}}
|
|
|
|
struct a {
|
|
int a : -1; // expected-error{{bit-field 'a' has negative width}}
|
|
|
|
// rdar://6081627
|
|
int b : 33; // expected-error{{width of bit-field 'b' (33 bits) exceeds the width of its type (32 bits)}}
|
|
|
|
int c : (1 + 0.25); // expected-error{{integer constant expression must have integer type}}
|
|
int d : (int)(1 + 0.25);
|
|
|
|
// rdar://6138816
|
|
int e : 0; // expected-error {{bit-field 'e' has zero width}}
|
|
|
|
float xx : 4; // expected-error {{bit-field 'xx' has non-integral type}}
|
|
|
|
// PR3607
|
|
enum e0 f : 1; // expected-error {{field has incomplete type 'enum e0'}}
|
|
|
|
int g : (_Bool)1;
|
|
|
|
// PR4017
|
|
char : 10; // expected-error {{width of anonymous bit-field (10 bits) exceeds the width of its type (8 bits)}}
|
|
unsigned : -2; // expected-error {{anonymous bit-field has negative width (-2)}}
|
|
float : 12; // expected-error {{anonymous bit-field has non-integral type 'float'}}
|
|
|
|
_Bool : 2; // expected-error {{width of anonymous bit-field (2 bits) exceeds the width of its type (1 bit)}}
|
|
_Bool h : 5; // expected-error {{width of bit-field 'h' (5 bits) exceeds the width of its type (1 bit)}}
|
|
};
|
|
|
|
struct b {unsigned x : 2;} x;
|
|
__typeof__(x.x+1) y;
|
|
int y;
|
|
|
|
struct {unsigned x : 2;} x2;
|
|
__typeof__((x.x+=1)+1) y;
|
|
__typeof__((0,x.x)+1) y;
|
|
__typeof__(x.x<<1) y;
|
|
int y;
|
|
|
|
struct PR8025 {
|
|
double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
|
|
};
|
|
|
|
struct Test4 {
|
|
unsigned bitX : 4;
|
|
unsigned bitY : 4;
|
|
unsigned var;
|
|
};
|
|
void test4(struct Test4 *t) {
|
|
(void) sizeof(t->bitX); // expected-error {{invalid application of 'sizeof' to bit-field}}
|
|
(void) sizeof((t->bitY)); // expected-error {{invalid application of 'sizeof' to bit-field}}
|
|
(void) sizeof(t->bitX = 4); // not a bitfield designator in C
|
|
(void) sizeof(t->bitX += 4); // not a bitfield designator in C
|
|
(void) sizeof((void) 0, t->bitX); // not a bitfield designator in C
|
|
(void) sizeof(t->var ? t->bitX : t->bitY); // not a bitfield designator in C
|
|
(void) sizeof(t->var ? t->bitX : t->bitX); // not a bitfield designator in C
|
|
}
|
|
|
|
typedef unsigned Unsigned;
|
|
typedef signed Signed;
|
|
|
|
struct Test5 { unsigned n : 2; } t5;
|
|
// Bitfield is unsigned
|
|
struct Test5 sometest5 = {-1};
|
|
typedef __typeof__(+t5.n) Signed; // ... but promotes to signed.
|
|
|
|
typedef __typeof__(t5.n + 0) Signed; // Arithmetic promotes.
|
|
|
|
typedef __typeof__(+(t5.n = 0)) Signed; // FIXME: Assignment should not; the result
|
|
typedef __typeof__(+(t5.n += 0)) Signed; // is a non-bit-field lvalue of type unsigned.
|
|
typedef __typeof__(+(t5.n *= 0)) Signed;
|
|
|
|
typedef __typeof__(+(++t5.n)) Signed; // FIXME: Increment is equivalent to compound-assignment.
|
|
typedef __typeof__(+(--t5.n)) Signed; // This should not promote to signed.
|
|
|
|
typedef __typeof__(+(t5.n++)) Unsigned; // Post-increment is underspecified, but seems to
|
|
typedef __typeof__(+(t5.n--)) Unsigned; // also act like compound-assignment.
|
|
|
|
struct Test6 {
|
|
: 0.0; // expected-error{{type name requires a specifier or qualifier}}
|
|
};
|
|
|
|
struct PR36157 {
|
|
int n : 1 ? 1 : implicitly_declare_function(); // expected-error {{call to undeclared function 'implicitly_declare_function'; ISO C99 and later do not support implicit function declarations}}
|
|
};
|