Implement SD-6: SG10 Feature Test Recommendations

2014-10-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement SD-6: SG10 Feature Test Recommendations
	* internal.h (lexer_state, spec_nodes): Add in__has_include__.
	* directives.c: Support __has_include__ builtin.
	* expr.c (parse_has_include): New function to parse __has_include__
	builtin; (eval_token()): Use it.
	* files.c (_cpp_has_header()): New funtion to look for header;
	(open_file_failed()): Not an error to not find a header file for
	__has_include__.
	* identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__.
	* pch.c (cpp_read_state): Lookup __has_include__.
	* traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through
	__has_include__ statements.

2014-10-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement SD-6: SG10 Feature Test Recommendations
	* c-cppbuiltin.c (c_cpp_builtins()): Define language feature
	macros and the __has_header macro.

2014-10-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement SD-6: SG10 Feature Test Recommendations
	* include/bits/basic_string.h: Add __cpp_lib feature test macro.
	* include/bits/stl_algobase.h: Ditto.
	* include/bits/stl_function.h: Ditto.
	* include/bits/unique_ptr.h: Ditto.
	* include/std/chrono: Ditto.
	* include/std/complex: Ditto.
	* include/std/iomanip: Ditto.
	* include/std/shared_mutex: Ditto.
	* include/std/tuple: Ditto.
	* include/std/type_traits: Ditto.
	* include/std/utility: Ditto.
	* testsuite/experimental/feat-cxx14.cc: New.
	* testsuite/experimental/feat-lib-fund.cc: New.
	* testsuite/20_util/declval/requirements/1_neg.cc: Adjust.
	* testsuite/20_util/duration/literals/range.cc: Adjust.
	* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust.
	* testsuite/20_util/duration/requirements/typedefs_neg2.cc: Adjust.
	* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Adjust.
	* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust.
	* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust.
	* testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc:
	Adjust.

2014-10-01  Edward Smith-Rowland  <3dw4rd@verizon.net>

	Implement SD-6: SG10 Feature Test Recommendations
	* g++.dg/cpp1y/feat-cxx11-neg.C: New.
	* g++.dg/cpp1y/feat-cxx11.C: New.
	* g++.dg/cpp1y/feat-cxx14.C: New.
	* g++.dg/cpp1y/feat-cxx98.C: New.
	* g++.dg/cpp1y/feat-cxx98-neg.C: New.
	* g++.dg/cpp1y/phoobhar.h: New.
	* g++.dg/cpp1y/testinc/phoobhar.h: New.

From-SVN: r215752
This commit is contained in:
Edward Smith-Rowland 2014-10-01 11:49:23 +00:00 committed by Edward Smith-Rowland
parent 5fbb36f4a4
commit a15f7cb8b8
41 changed files with 820 additions and 16 deletions

View file

@ -1,3 +1,18 @@
2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net>
Implement SD-6: SG10 Feature Test Recommendations
* internal.h (lexer_state, spec_nodes): Add in__has_include__.
* directives.c: Support __has_include__ builtin.
* expr.c (parse_has_include): New function to parse __has_include__
builtin; (eval_token()): Use it.
* files.c (_cpp_has_header()): New funtion to look for header;
(open_file_failed()): Not an error to not find a header file for
__has_include__.
* identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__.
* pch.c (cpp_read_state): Lookup __has_include__.
* traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through
__has_include__ statements.
2014-09-30 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR preprocessor/58893

View file

@ -566,6 +566,11 @@ lex_macro_node (cpp_reader *pfile, bool is_def_or_undef)
if (is_def_or_undef && node == pfile->spec_nodes.n_defined)
cpp_error (pfile, CPP_DL_ERROR,
"\"defined\" cannot be used as a macro name");
else if (is_def_or_undef
&& (node == pfile->spec_nodes.n__has_include__
|| node == pfile->spec_nodes.n__has_include_next__))
cpp_error (pfile, CPP_DL_ERROR,
"\"__has_include__\" cannot be used as a macro name");
else if (! (node->flags & NODE_POISONED))
return node;
}
@ -2623,3 +2628,12 @@ _cpp_init_directives (cpp_reader *pfile)
node->directive_index = i;
}
}
/* Extract header file from a bracket include. Parsing starts after '<'.
The string is malloced and must be freed by the caller. */
char *
_cpp_bracket_include(cpp_reader *pfile)
{
return glue_header_name (pfile);
}

View file

@ -64,6 +64,8 @@ static unsigned int interpret_float_suffix (cpp_reader *, const uchar *, size_t)
static unsigned int interpret_int_suffix (cpp_reader *, const uchar *, size_t);
static void check_promotion (cpp_reader *, const struct op *);
static cpp_num parse_has_include (cpp_reader *, enum include_type);
/* Token type abuse to create unary plus and minus operators. */
#define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
#define CPP_UMINUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 2))
@ -1048,6 +1050,10 @@ eval_token (cpp_reader *pfile, const cpp_token *token,
case CPP_NAME:
if (token->val.node.node == pfile->spec_nodes.n_defined)
return parse_defined (pfile);
else if (token->val.node.node == pfile->spec_nodes.n__has_include__)
return parse_has_include (pfile, IT_INCLUDE);
else if (token->val.node.node == pfile->spec_nodes.n__has_include_next__)
return parse_has_include (pfile, IT_INCLUDE_NEXT);
else if (CPP_OPTION (pfile, cplusplus)
&& (token->val.node.node == pfile->spec_nodes.n_true
|| token->val.node.node == pfile->spec_nodes.n_false))
@ -2072,3 +2078,72 @@ num_div_op (cpp_reader *pfile, cpp_num lhs, cpp_num rhs, enum cpp_ttype op,
return lhs;
}
/* Handle meeting "__has_include__" in a preprocessor expression. */
static cpp_num
parse_has_include (cpp_reader *pfile, enum include_type type)
{
cpp_num result;
bool paren = false;
cpp_hashnode *node = 0;
const cpp_token *token;
bool bracket = false;
char *fname = 0;
result.unsignedp = false;
result.high = 0;
result.overflow = false;
result.low = 0;
pfile->state.in__has_include__++;
token = cpp_get_token (pfile);
if (token->type == CPP_OPEN_PAREN)
{
paren = true;
token = cpp_get_token (pfile);
}
if (token->type == CPP_STRING || token->type == CPP_HEADER_NAME)
{
if (token->type == CPP_HEADER_NAME)
bracket = true;
fname = XNEWVEC (char, token->val.str.len - 1);
memcpy (fname, token->val.str.text + 1, token->val.str.len - 2);
fname[token->val.str.len - 2] = '\0';
node = token->val.node.node;
}
else if (token->type == CPP_LESS)
{
bracket = true;
fname = _cpp_bracket_include (pfile);
}
else
cpp_error (pfile, CPP_DL_ERROR,
"operator \"__has_include__\" requires a header string");
if (fname)
{
int angle_brackets = (bracket ? 1 : 0);
if (_cpp_has_header (pfile, fname, angle_brackets, type))
result.low = 1;
else
result.low = 0;
XDELETEVEC (fname);
}
if (paren && cpp_get_token (pfile)->type != CPP_CLOSE_PAREN)
cpp_error (pfile, CPP_DL_ERROR,
"missing ')' after \"__has_include__\"");
/* A possible controlling macro of the form #if !__has_include__ ().
_cpp_parse_expr checks there was no other junk on the line. */
if (node)
pfile->mi_ind_cmacro = node;
pfile->state.in__has_include__--;
return result;
}

View file

@ -1041,6 +1041,9 @@ open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets)
int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffer->sysp : 0;
bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp);
if (pfile->state.in__has_include__)
return;
errno = file->err_no;
if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
{
@ -1957,3 +1960,18 @@ check_file_against_entries (cpp_reader *pfile ATTRIBUTE_UNUSED,
return bsearch (&d, pchf->entries, pchf->count, sizeof (struct pchf_entry),
pchf_compare) != NULL;
}
/* Return true if the file FNAME is found in the appropriate include file path
as indicated by ANGLE_BRACKETS. */
bool
_cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets,
enum include_type type)
{
cpp_dir *start_dir = search_path_head (pfile, fname, angle_brackets, type);
_cpp_file *file = _cpp_find_file (pfile, fname, start_dir,
/*fake=*/false, angle_brackets,
/*implicit_preinclude=*/false);
return file->err_no != ENOENT;
}

View file

@ -72,6 +72,8 @@ _cpp_init_hashtable (cpp_reader *pfile, cpp_hash_table *table)
s->n_false = cpp_lookup (pfile, DSC("false"));
s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__"));
s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
s->n__has_include__ = cpp_lookup (pfile, DSC("__has_include__"));
s->n__has_include_next__ = cpp_lookup (pfile, DSC("__has_include_next__"));
}
/* Tear down the identifier hash table. */

View file

@ -258,6 +258,9 @@ struct lexer_state
/* Nonzero when parsing arguments to a function-like macro. */
unsigned char parsing_args;
/* Nonzero if in a __has_include__ or __has_include_next__ statement. */
unsigned char in__has_include__;
/* Nonzero if prevent_expansion is true only because output is
being discarded. */
unsigned char discarding_output;
@ -279,6 +282,8 @@ struct spec_nodes
cpp_hashnode *n_true; /* C++ keyword true */
cpp_hashnode *n_false; /* C++ keyword false */
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
cpp_hashnode *n__has_include__; /* __has_include__ operator */
cpp_hashnode *n__has_include_next__; /* __has_include_next__ operator */
};
typedef struct _cpp_line_note _cpp_line_note;
@ -645,6 +650,8 @@ extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
extern const char *_cpp_get_file_name (_cpp_file *);
extern struct stat *_cpp_get_file_stat (_cpp_file *);
extern bool _cpp_has_header (cpp_reader *, const char *, int,
enum include_type);
/* In expr.c */
extern bool _cpp_parse_expr (cpp_reader *, bool);
@ -680,6 +687,7 @@ extern void _cpp_init_internal_pragmas (cpp_reader *);
extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
linenum_type, unsigned int);
extern void _cpp_pop_buffer (cpp_reader *);
extern char *_cpp_bracket_include (cpp_reader *);
/* In directives.c */
struct _cpp_dir_only_callbacks

View file

@ -833,6 +833,8 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
s->n_true = cpp_lookup (r, DSC("true"));
s->n_false = cpp_lookup (r, DSC("false"));
s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__"));
s->n__has_include__ = cpp_lookup (r, DSC("__has_include__"));
s->n__has_include_next__ = cpp_lookup (r, DSC("__has_include_next__"));
}
old_state = r->state;

View file

@ -74,7 +74,9 @@ enum ls {ls_none = 0, /* Normal state. */
ls_defined_close, /* Looking for ')' of defined(). */
ls_hash, /* After # in preprocessor conditional. */
ls_predicate, /* After the predicate, maybe paren? */
ls_answer}; /* In answer to predicate. */
ls_answer, /* In answer to predicate. */
ls_has_include, /* After __has_include__. */
ls_has_include_close}; /* Looking for ')' of __has_include__. */
/* Lexing TODO: Maybe handle space in escaped newlines. Stop lex.c
from recognizing comments and directives during its lexing pass. */
@ -524,6 +526,13 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_defined;
continue;
}
else if (pfile->state.in_expression
&& (node == pfile->spec_nodes.n__has_include__
|| node == pfile->spec_nodes.n__has_include_next__))
{
lex_state = ls_has_include;
continue;
}
}
break;
@ -547,6 +556,8 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_answer;
else if (lex_state == ls_defined)
lex_state = ls_defined_close;
else if (lex_state == ls_has_include)
lex_state = ls_has_include_close;
}
break;
@ -584,7 +595,8 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
goto new_context;
}
}
else if (lex_state == ls_answer || lex_state == ls_defined_close)
else if (lex_state == ls_answer || lex_state == ls_defined_close
|| lex_state == ls_has_include_close)
lex_state = ls_none;
}
break;
@ -665,7 +677,8 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_none;
else if (lex_state == ls_hash
|| lex_state == ls_predicate
|| lex_state == ls_defined)
|| lex_state == ls_defined
|| lex_state == ls_has_include)
lex_state = ls_none;
/* ls_answer and ls_defined_close keep going until ')'. */