diff --git a/preprocess.c b/preprocess.c index f32677b..7dba0bc 100644 --- a/preprocess.c +++ b/preprocess.c @@ -1016,6 +1016,9 @@ static char *read_include_filename(Token *tok, bool *is_dquote) { } static Token *include_file(Token *tok, char *path, Token *filename_tok, int *incl_no) { + if (!path) + error_tok(filename_tok, "file not found"); + // Check for "#pragma once" if (hashmap_get(&pragma_once, path)) return tok; @@ -1191,7 +1194,7 @@ static Token *directives(Token **cur, Token *start, bool is_root) { char *filename = read_include_filename(split_line(&tok, tok->next), &is_dquote); int incl_no = -1; char *path = search_include_paths2(filename, start, is_dquote, &incl_no); - return include_file(tok, path ? path : filename, start->next->next, &incl_no); + return include_file(tok, path, start->next->next, &incl_no); } if (equal(tok, "include_next")) { @@ -1201,9 +1204,6 @@ static Token *directives(Token **cur, Token *start, bool is_root) { int incl_no = tok->file->incl_no + 1; char *filename = read_include_filename(split_line(&tok, tok->next), &(bool){0}); char *path = search_include_next(filename, &incl_no); - if (!path) - error_tok(start->next->next, "%s: cannot open file: %s", filename, strerror(errno)); - return include_file(tok, path, start->next->next, &incl_no); } diff --git a/test/driver.sh b/test/driver.sh index 4cbc477..eee1d08 100644 --- a/test/driver.sh +++ b/test/driver.sh @@ -95,6 +95,11 @@ check -I echo "#include \"i-option-test\"" | $testcc -I $tmp/dir -E -xc - | grep -q foo check -I +# pragma once +printf "#pragma once\n#ifdef A\n#error\n#endif\n#define A\n" > $tmp/inc.h +printf "#include \"inc.h\"\n#include \"inc.h\"" | $testcc -xc - -E -I$tmp -o/dev/null +check "pragma once" + # -D echo foo | $testcc -Dfoo -E -xc - | grep -q 1 check -D diff --git a/test/pragma-once.c b/test/pragma-once.c deleted file mode 100644 index 263a2eb..0000000 --- a/test/pragma-once.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "test.h" - -#pragma once - -#include "test/pragma-once.c" - -int main() { - printf("OK\n"); - return 0; -}