blob: 1f2e884a5882bdfe10217a4c5a50540c888e3599 [file] [log] [blame]
Ted Kremenekc85a4772011-10-12 20:06:09 +00001// RUN: %clang_cc1 -fsyntax-only %s -verify
2#ifndef __has_warning
3#error Should have __has_warning
4#endif
5
6#if __has_warning("not valid") // expected-warning {{__has_warning expected option name}}
7#endif
8
Jordan Roseb13eb8d2012-07-11 19:58:23 +00009// expected-warning@+2 {{Should have -Wparentheses}}
Ted Kremenekc85a4772011-10-12 20:06:09 +000010#if __has_warning("-Wparentheses")
Jordan Roseb13eb8d2012-07-11 19:58:23 +000011#warning Should have -Wparentheses
Ted Kremenekc85a4772011-10-12 20:06:09 +000012#endif
13
Andy Gibbsa8df57a2012-11-17 19:16:52 +000014// expected-error@+2 {{expected string literal in '__has_warning'}}
Andy Gibbs50b6cef2016-04-05 08:36:47 +000015// expected-error@+1 {{missing ')'}} expected-note@+1 {{match}}
Andy Gibbsf591982b2012-11-17 19:14:53 +000016#if __has_warning(-Wfoo)
Ted Kremenekc85a4772011-10-12 20:06:09 +000017#endif
18
Jordan Roseb13eb8d2012-07-11 19:58:23 +000019// expected-warning@+3 {{Not a valid warning flag}}
Ted Kremenekc85a4772011-10-12 20:06:09 +000020#if __has_warning("-Wnot-a-valid-warning-flag-at-all")
21#else
Jordan Roseb13eb8d2012-07-11 19:58:23 +000022#warning Not a valid warning flag
23#endif
Andy Gibbs58905d22012-11-17 19:15:38 +000024
Andy Gibbs50b6cef2016-04-05 08:36:47 +000025// expected-error@+1 {{missing '(' after '__has_warning'}}
Andy Gibbs58905d22012-11-17 19:15:38 +000026#if __has_warning "not valid"
27#endif
28
29// Macro expansion does not occur in the parameter to __has_warning
30// (as is also expected behaviour for ordinary macros), so the
31// following should not expand:
32
33#define MY_ALIAS "-Wparentheses"
34
Andy Gibbs50b6cef2016-04-05 08:36:47 +000035// expected-error@+1 {{expected}}
Andy Gibbs58905d22012-11-17 19:15:38 +000036#if __has_warning(MY_ALIAS)
37#error Alias expansion not allowed
38#endif
39
40// But deferring should expand:
41#define HAS_WARNING(X) __has_warning(X)
42
43#if !HAS_WARNING(MY_ALIAS)
44#error Expansion should have occurred
45#endif