tinycc/tests/tests2/129_scopes.c
herman ten brugge e6ea0d0424
Some checks are pending
build and test / test-x86_64-linux (push) Waiting to run
build and test / test-x86_64-osx (push) Waiting to run
build and test / test-aarch64-osx (push) Waiting to run
build and test / test-x86_64-win32 (push) Waiting to run
build and test / test-i386-win32 (push) Waiting to run
build and test / test-armv7-linux (push) Waiting to run
build and test / test-aarch64-linux (push) Waiting to run
build and test / test-riscv64-linux (push) Waiting to run
tccgen: fix several problems
Fix 'void func2(char *(*md)(char *md))' declaration.
Fix global array and local extern array problems.
Fix scope problem with old function declaration.
Fix 'typedef int t[]' declaration. Empty size should remain.
2025-08-30 07:13:49 +02:00

124 lines
2.1 KiB
C

int printf(const char*, ...);
#define myassert(x) \
printf("%s:%d: %s : \"%s\"\n", __FILE__,__LINE__,(x)?"ok":"error",#x)
enum{ in = 0};
int main_1(){
{
myassert(!in);
if(sizeof(enum{in=1})) myassert(in);
myassert(!in); //OOPS
}
{
myassert(!in);
switch(sizeof(enum{in=1})) { default: myassert(in); }
myassert(!in); //OOPS
}
{
myassert(!in);
while(sizeof(enum{in=1})) { myassert(in); break; }
myassert(!in); //OOPS
}
{
myassert(!in);
do{ myassert(!in);}while(0*sizeof(enum{in=1}));
myassert(!in); //OOPS
}
{
myassert(!in);
for(sizeof(enum{in=1});;){ myassert(in); break; }
myassert(!in); //OK
}
{
myassert(!in);
for(;;sizeof(enum{in=1})){ myassert(in); break; }
myassert(!in); //OK
}
{
myassert(!in);
for(;sizeof(enum{in=1});){ myassert(in); break; }
myassert(!in); //OK
}
return 0;
}
/* --------------------------------------------- */
int main_2()
{
char c = 'a';
void func1(char c); /* param 'c' must not shadow local 'c' */
func1(c);
return 0;
}
void func1(char c)
{
myassert(c == 'a');
}
struct st { int a; };
/* --------------------------------------------- */
int main_3()
{
struct st func(void);
struct st st = func(); /* not an 'incompatible redefinition' */
myassert(st.a == 10);
return 0;
}
struct st func(void)
{
struct st st = { 10 };
return st;
}
/* --------------------------------------------- */
static void func2(char *(*md)(char *md))
{
(*md)("test");
}
static char *a(char *a)
{
printf("%s\n", a);
return a;
}
int main_4(void)
{
func2(a);
return 0;
}
/* --------------------------------------------- */
int b[3];
int f(void);
int main_5(void)
{
extern int b[3];
b[2]=10;
printf("%d\n", f());
return 0;
}
int f(void)
{
return b[2]==10 ? 1 : 0;
}
/* --------------------------------------------- */
int main()
{
main_1();
main_2();
main_3();
main_4();
main_5();
return 0;
}