From 06b2192aa2bb6698c863388c5d085ba5b1f28374 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 9 Oct 2017 13:38:33 -0700 Subject: Preprocessor: fix `undef` and redefinition (#204) * Preprocessor: fix `undef` and redefinition The logic for `undef` directives was failing to suppress macro expansion when reading the name to un-define, and so it wasn't actually working at all. We didn't notice this because we didn't have a test case, and users hadn't tried it. The logic for `define` had a similar bug, which meant that any attempt to define an already-defined macro would fail with a cryptic error, rather than raising the intended warning. Test cases have been added for both issues, along with the fixes. * fixup: add expected output for tests added --- tests/preprocessor/undef.slang | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/preprocessor/undef.slang (limited to 'tests/preprocessor/undef.slang') diff --git a/tests/preprocessor/undef.slang b/tests/preprocessor/undef.slang new file mode 100644 index 000000000..42ce05be7 --- /dev/null +++ b/tests/preprocessor/undef.slang @@ -0,0 +1,32 @@ +//TEST:SIMPLE: +// #undef support + +// warning: undef of something not defined +#undef FOO + +#define BAR 1.0f + +float foo() { return BAR + 2.0; } + +#ifdef BAR +// okay +#else +#error not okay +#endif + +#undef BAR + +typedef float BAR; + +BAR bar() { return 2.0; } + +#if !defined(BAR) +// okay +#else +#error not okay +#endif + + +#define FOO + +#undef FOO -- cgit v1.2.3