Skip to content

Commit b4064e6

Browse files
committed
Support empty alias, refine include guard tests
1 parent 005956a commit b4064e6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/parser.c

+4
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ bool read_preproc_directive()
409409

410410
macro->start_source_idx = source_idx;
411411
skip_macro_body();
412+
} else {
413+
/* Empty alias, may be dummy alias serves as include guard */
414+
value[0] = 0;
415+
add_alias(alias, value);
412416
}
413417

414418
return true;

tests/driver.sh

+41-1
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,49 @@ try_ 0 << EOF
465465
#else
466466
#define A 1
467467
#endif
468+
469+
#ifndef A
470+
#define B 1
471+
#else
472+
#define B 0
473+
#endif
468474
int main()
469475
{
470-
return A;
476+
return A + B;
477+
}
478+
EOF
479+
480+
# include guard test, simulates inclusion of a file named defs.h and global.c
481+
try_ 0 << EOF
482+
/* #include "defs.h" */
483+
#ifndef DEFS_H
484+
#define DEFS_H
485+
486+
#define A 1
487+
488+
#endif
489+
/* end if "defs.h" inclusion */
490+
491+
/* #include "global.c" */
492+
#ifndef GLOBAL_C
493+
#define GLOBAL_C
494+
495+
#define B 1
496+
497+
/* [global.c] #include "defs.h" */
498+
#ifndef DEFS_H
499+
#define DEFS_H
500+
501+
#define A 2
502+
503+
#endif
504+
/* end if "defs.h" inclusion */
505+
#endif
506+
/* end if "global.c" inclusion */
507+
508+
int main()
509+
{
510+
return A - B;
471511
}
472512
EOF
473513

0 commit comments

Comments
 (0)