2010-11-16 18:26:08 +08:00
// RUN: %clang_cc1 -ffreestanding -Eonly -verify %s
2009-11-03 06:28:12 +08:00
// Try different path permutations of __has_include with existing file.
2010-11-16 18:26:08 +08:00
# if __has_include("stdint.h")
2009-11-03 06:28:12 +08:00
# else
# error "__has_include failed (1)."
# endif
2010-11-16 18:26:08 +08:00
# if __has_include(<stdint.h>)
2009-11-03 06:28:12 +08:00
# else
# error "__has_include failed (2)."
# endif
// Try unary expression.
2010-11-16 18:26:08 +08:00
# if !__has_include("stdint.h")
2009-11-03 06:28:12 +08:00
# error "__has_include failed (5)."
# endif
// Try binary expression.
2010-11-16 18:26:08 +08:00
# if __has_include("stdint.h") && __has_include("stddef.h")
2009-11-03 06:28:12 +08:00
# else
# error "__has_include failed (6)."
# endif
// Try non-existing file.
# if __has_include("blahblah.h")
# error "__has_include failed (7)."
# endif
// Try defined.
# if !defined(__has_include)
# error "defined(__has_include) failed (8)."
# endif
// Try different path permutations of __has_include_next with existing file.
# if __has_include_next("stddef.h") // expected-warning {{#include_next in primary source file}}
# else
# error "__has_include failed (1)."
# endif
# if __has_include_next(<stddef.h>) // expected-warning {{#include_next in primary source file}}
# else
# error "__has_include failed (2)."
# endif
// Try unary expression.
2010-11-16 18:26:08 +08:00
# if !__has_include_next("stdint.h") // expected-warning {{#include_next in primary source file}}
2009-11-03 06:28:12 +08:00
# error "__has_include_next failed (5)."
# endif
// Try binary expression.
2010-11-16 18:26:08 +08:00
# if __has_include_next("stdint.h") && __has_include("stddef.h") // expected-warning {{#include_next in primary source file}}
2009-11-03 06:28:12 +08:00
# else
# error "__has_include_next failed (6)."
# endif
// Try non-existing file.
# if __has_include_next("blahblah.h") // expected-warning {{#include_next in primary source file}}
# error "__has_include_next failed (7)."
# endif
// Try defined.
# if !defined(__has_include_next)
# error "defined(__has_include_next) failed (8)."
# endif
2013-01-09 10:20:00 +08:00
// Fun with macros
# define MACRO1 __has_include(<stdint.h>)
# define MACRO2 ("stdint.h")
# define MACRO3 ("blahblah.h")
# define MACRO4 blahblah.h>)
# define MACRO5 <stdint.h>
# if !MACRO1
# error "__has_include with macro failed (1)."
# endif
# if !__has_include MACRO2
# error "__has_include with macro failed (2)."
# endif
# if __has_include MACRO3
# error "__has_include with macro failed (3)."
# endif
# if __has_include(<MACRO4
# error "__has_include with macro failed (4)."
# endif
# if !__has_include(MACRO5)
# error "__has_include with macro failed (2)."
# endif
2013-01-17 03:32:21 +08:00
// Try as non-preprocessor directives
void foo ( void ) {
2018-03-28 12:16:13 +08:00
__has_include_next ( " stdint.h " ) // expected-warning {{#include_next in primary source file}} expected-error {{'__has_include_next' must be used within a preprocessing directive}}
__has_include ( " stdint.h " ) // expected-error {{'__has_include' must be used within a preprocessing directive}}
2013-01-17 03:32:21 +08:00
}
2018-03-28 12:16:13 +08:00
MACRO1 // expected-error {{'__has_include' must be used within a preprocessing directive}}
2013-01-17 03:32:21 +08:00
# if 1
2018-03-28 12:16:13 +08:00
MACRO1 // expected-error {{'__has_include' must be used within a preprocessing directive}}
2013-01-17 03:32:21 +08:00
# endif
#if 0
# elif 1
2018-03-28 12:16:13 +08:00
MACRO1 // expected-error {{'__has_include' must be used within a preprocessing directive}}
2013-01-17 03:32:21 +08:00
# endif
#if 0
MACRO1 // This should be fine because it is never actually reached
# endif
2009-11-03 06:28:12 +08:00
// Try badly formed expressions.
2012-07-12 04:12:19 +08:00
// FIXME: We can recover better in almost all of these cases. (PR13335)
2012-10-23 04:28:48 +08:00
// expected-error@+1 {{missing '(' after '__has_include'}}
2012-07-12 04:12:19 +08:00
# if __has_include "stdint.h")
# endif
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
# if __has_include(stdint.h)
# endif
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}}
# if __has_include()
# endif
// expected-error@+1 {{missing '(' after '__has_include'}}
# if __has_include)
# endif
2012-10-23 04:28:48 +08:00
// expected-error@+1 {{missing '(' after '__has_include'}}
2012-07-12 04:12:19 +08:00
# if __has_include<stdint.h>)
# endif
2012-10-23 04:28:48 +08:00
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-warning@+1 {{missing terminating '"' character}} expected-error@+1 {{invalid token at start of a preprocessor expression}}
2012-07-12 04:12:19 +08:00
# if __has_include("stdint.h)
# endif
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-warning@+1 {{missing terminating '"' character}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
# if __has_include(stdint.h")
# endif
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
# if __has_include(stdint.h>)
# endif
2018-03-28 12:16:13 +08:00
// expected-error@+1 {{'__has_include' must be used within a preprocessing directive}}
2012-10-23 04:28:48 +08:00
__has_include
// expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
# if __has_include("stdint.h"
# endif
2012-07-12 04:12:19 +08:00
2012-10-23 04:28:48 +08:00
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} // expected-error@+1 {{expected value in expression}}
# if __has_include(
# endif
2012-07-12 04:12:19 +08:00
2012-10-23 04:28:48 +08:00
// expected-error@+1 {{missing '(' after '__has_include'}} // expected-error@+1 {{expected value in expression}}
# if __has_include
# endif
2015-03-29 23:33:29 +08:00
// expected-error@+1 {{missing '(' after '__has_include'}}
# if __has_include'x'
# endif
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}}
# if __has_include('x'
# endif
// expected-error@+1 {{expected "FILENAME" or <FILENAME}} expected-error@+1 {{expected end of line in preprocessor expression}}
# if __has_include('x')
# endif
2012-10-23 04:28:48 +08:00
// expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
# if __has_include(<stdint.h>
# endif
2019-03-19 09:51:19 +08:00
// expected-error@+1 {{expected '>'}} expected-note@+1 {{to match this '<'}} // expected-error@+1 {{expected value in expression}}
2012-10-23 04:28:48 +08:00
# if __has_include(<stdint.h)
# endif
2013-02-27 09:34:48 +08:00
# define HAS_INCLUDE(header) __has_include(header)
# if HAS_INCLUDE(<stdint.h>)
# else
# error "__has_include failed (9)."
# endif
2013-03-19 07:22:28 +08:00
# if FOO
# elif __has_include(<foo>)
# endif
// PR15539
# ifdef FOO
# elif __has_include(<foo>)
# endif