| 1 |
/* Copyright 2007 Free Software Foundation, Inc. |
| 2 |
Contributed by Ollie Wild <[email protected]>. */ |
| 3 |
|
| 4 |
/* { dg-do preprocess } */ |
| 5 |
/* { dg-options -fdirectives-only } */ |
| 6 |
|
| 7 |
/* Tests scan_translation_unit_directives_only()'s handling of corner cases. */ |
| 8 |
|
| 9 |
/* Ignore directives inside block comments... |
| 10 |
#error directive inside block comment |
| 11 |
*/ |
| 12 |
|
| 13 |
// Escaped newline doesn't terminate line comment \ |
| 14 |
#error directive inside line comment |
| 15 |
|
| 16 |
/* A comment canot start inside a string. */ |
| 17 |
const char *c1 = "/*"; |
| 18 |
#define NOT_IN_COMMENT |
| 19 |
const char *c2 = "*/"; |
| 20 |
#ifndef NOT_IN_COMMENT |
| 21 |
#error Comment started inside a string literal |
| 22 |
#endif |
| 23 |
|
| 24 |
/* Escaped newline handling. */ |
| 25 |
int i; \ |
| 26 |
#error ignored escaped newline |
| 27 |
\ |
| 28 |
\ |
| 29 |
#define BOL |
| 30 |
#ifndef BOL |
| 31 |
#error escaped newline did not preserve beginning of line |
| 32 |
#endif |
| 33 |
|
| 34 |
/* Handles \\ properly at the end of a string. */ |
| 35 |
"string ends in \\"/* |
| 36 |
#error Missed string terminator. |
| 37 |
*/ |
| 38 |
|
| 39 |
/* Handles macro expansion in preprocessing directives. */ |
| 40 |
#define HEADER "dir-only-1.h" |
| 41 |
#include HEADER |
| 42 |
#ifndef GOT_HEADER |
| 43 |
#error Failed to include header. |
| 44 |
#endif |
| 45 |
|
| 46 |
/\ |
| 47 |
* |
| 48 |
#define IN_COMMENT |
| 49 |
*/ |
| 50 |
#ifdef IN_COMMENT |
| 51 |
#error Escaped newline breaks block comment initiator. |
| 52 |
#endif |
| 53 |
|
| 54 |
/* |
| 55 |
*\ |
| 56 |
/ |
| 57 |
#define NOT_IN_COMMENT2 |
| 58 |
/**/ |
| 59 |
#ifndef NOT_IN_COMMENT2 |
| 60 |
#error Escaped newline breaks block comment terminator. |
| 61 |
#endif |
| 62 |
|
| 63 |
/* Test escaped newline inside character escape sequence. */ |
| 64 |
"\\ |
| 65 |
\"/* |
| 66 |
#error Missed string terminator |
| 67 |
*/ |
| 68 |
|
| 69 |
/* Block comments don't mask trailing preprocessing |
| 70 |
directive. */ #define NOT_MASKED |
| 71 |
#ifndef NOT_MASKED |
| 72 |
#error Comment masks trailing directive. |
| 73 |
#endif |