From a37b3539d94c434c5d74ab524eae2988e48e0756 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 19 Sep 2018 08:32:28 -0700 Subject: Warn when undefined identifier used in preprocessor conditional (#642) This can mask an error when the user either typos a macro name when writing a conditional, or (as was the case for the user who pointed out this issue) they mistakenly assume that a `#define` in an `import`ed file has been made visible to them. This change just adds the warning in the obvious place, with a test code to ensure it triggers. --- tests/diagnostics/undefined-in-preprocessor-conditional.slang | 10 ++++++++++ .../undefined-in-preprocessor-conditional.slang.expected | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/diagnostics/undefined-in-preprocessor-conditional.slang create mode 100644 tests/diagnostics/undefined-in-preprocessor-conditional.slang.expected (limited to 'tests') diff --git a/tests/diagnostics/undefined-in-preprocessor-conditional.slang b/tests/diagnostics/undefined-in-preprocessor-conditional.slang new file mode 100644 index 000000000..d46c68d33 --- /dev/null +++ b/tests/diagnostics/undefined-in-preprocessor-conditional.slang @@ -0,0 +1,10 @@ +//TEST(smoke):SIMPLE: + +// Use an undefined identifier in a preprocessor conditional + +#define FOO 1 +#define BORT 1 + +#if FOO && BART +#error Should not get here +#endif diff --git a/tests/diagnostics/undefined-in-preprocessor-conditional.slang.expected b/tests/diagnostics/undefined-in-preprocessor-conditional.slang.expected new file mode 100644 index 000000000..ac8be68a2 --- /dev/null +++ b/tests/diagnostics/undefined-in-preprocessor-conditional.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +tests/diagnostics/undefined-in-preprocessor-conditional.slang(8): warning 15205: undefined idenfier 'BART' in preprocessor expression will evaluate to zero +} +standard output = { +} -- cgit v1.2.3