teak-llvm/clang/test/Preprocessor/warning_tests.c
Andy Gibbs 50b6ceff1f Consolidate and improve the handling of built-in feature-like macros
Summary:
The parsing logic has been separated out from the macro implementation logic, leading to a number of improvements:

* Gracefully handle unexpected/invalid tokens, too few, too many and nested parameters
* Provide consistent behaviour between all built-in feature-like macros
* Simplify the implementation of macro logic
* Fix __is_identifier to correctly return '0' for non-identifiers

Reviewers: doug.gregor, rsmith

Subscribers: rsmith, cfe-commits

Differential Revision: http://reviews.llvm.org/D17149

llvm-svn: 265381
2016-04-05 08:36:47 +00:00

46 lines
1.2 KiB
C

// RUN: %clang_cc1 -fsyntax-only %s -verify
#ifndef __has_warning
#error Should have __has_warning
#endif
#if __has_warning("not valid") // expected-warning {{__has_warning expected option name}}
#endif
// expected-warning@+2 {{Should have -Wparentheses}}
#if __has_warning("-Wparentheses")
#warning Should have -Wparentheses
#endif
// expected-error@+2 {{expected string literal in '__has_warning'}}
// expected-error@+1 {{missing ')'}} expected-note@+1 {{match}}
#if __has_warning(-Wfoo)
#endif
// expected-warning@+3 {{Not a valid warning flag}}
#if __has_warning("-Wnot-a-valid-warning-flag-at-all")
#else
#warning Not a valid warning flag
#endif
// expected-error@+1 {{missing '(' after '__has_warning'}}
#if __has_warning "not valid"
#endif
// Macro expansion does not occur in the parameter to __has_warning
// (as is also expected behaviour for ordinary macros), so the
// following should not expand:
#define MY_ALIAS "-Wparentheses"
// expected-error@+1 {{expected}}
#if __has_warning(MY_ALIAS)
#error Alias expansion not allowed
#endif
// But deferring should expand:
#define HAS_WARNING(X) __has_warning(X)
#if !HAS_WARNING(MY_ALIAS)
#error Expansion should have occurred
#endif