aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2015-05-12 20:57:38 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2015-05-12 20:57:38 +0000
commitc3388e62499a6d2f931247a73cabf9184366248e (patch)
tree59ac6b4ba6d59fb6b6bc0da54eaa2c8c9b71068d /libcpp
parentf06ed65044c0cba7f9cb8d6d8a8b99ee81953e4e (diff)
Implement -Wmisleading-indentation
gcc/ChangeLog: * doc/invoke.texi (Warning Options): Add -Wmisleading-indentation. (-Wmisleading-indentation): New option. * Makefile.in (C_COMMON_OBJS): Add c-family/c-indentation.o. gcc/c-family/ChangeLog: * c-common.h (warn_for_misleading_indentation): New prototype. * c-indentation.c: New file. * c.opt (Wmisleading-indentation): New option. gcc/c/ChangeLog: * c-parser.c (c_parser_if_body): Add param "if_loc", use it to add a call to warn_for_misleading_indentation. (c_parser_else_body): Likewise, adding param "else_loc". (c_parser_if_statement): Check for misleading indentation. (c_parser_while_statement): Likewise. (c_parser_for_statement): Likewise. gcc/cp/ChangeLog: * parser.c (cp_parser_selection_statement): Add location and guard_kind arguments to calls to cp_parser_implicitly_scoped_statement. (cp_parser_iteration_statement): Likewise for calls to cp_parser_already_scoped_statement. (cp_parser_implicitly_scoped_statement): Add "guard_loc" and "guard_kind" params; use them to warn for misleading indentation. (cp_parser_already_scoped_statement): Likewise. gcc/testsuite/ChangeLog: * c-c++-common/Wmisleading-indentation.c: New testcase. * c-c++-common/Wmisleading-indentation-2.c: New testcase. * c-c++-common/Wmisleading-indentation-2.md: New file. libcpp/ChangeLog: * directives.c (do_line): Set seen_line_directive on line_table. (do_linemarker): Likewise. * include/line-map.h (struct line_maps): Add new field "seen_line_directive". From-SVN: r223098
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog7
-rw-r--r--libcpp/directives.c6
-rw-r--r--libcpp/include/line-map.h3
3 files changed, 14 insertions, 2 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 51304424753..c0f04ac0445 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2015-05-12 David Malcolm <dmalcolm@redhat.com>
+
+ * directives.c (do_line): Set seen_line_directive on line_table.
+ (do_linemarker): Likewise.
+ * include/line-map.h (struct line_maps): Add new field
+ "seen_line_directive".
+
2015-05-08 Jason Merrill <jason@redhat.com>
* include/cpplib.h: Add CPP_W_CXX11_COMPAT.
diff --git a/libcpp/directives.c b/libcpp/directives.c
index 2a824e6ed3f..356ec135100 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -911,7 +911,7 @@ strtolinenum (const uchar *str, size_t len, linenum_type *nump, bool *wrapped)
static void
do_line (cpp_reader *pfile)
{
- const struct line_maps *line_table = pfile->line_table;
+ struct line_maps *line_table = pfile->line_table;
const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
/* skip_rest_of_line() may cause line table to be realloc()ed so note down
@@ -965,6 +965,7 @@ do_line (cpp_reader *pfile)
skip_rest_of_line (pfile);
_cpp_do_file_change (pfile, LC_RENAME_VERBATIM, new_file, new_lineno,
map_sysp);
+ line_table->seen_line_directive = true;
}
/* Interpret the # 44 "file" [flags] notation, which has slightly
@@ -973,7 +974,7 @@ do_line (cpp_reader *pfile)
static void
do_linemarker (cpp_reader *pfile)
{
- const struct line_maps *line_table = pfile->line_table;
+ struct line_maps *line_table = pfile->line_table;
const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
const cpp_token *token;
const char *new_file = ORDINARY_MAP_FILE_NAME (map);
@@ -1052,6 +1053,7 @@ do_linemarker (cpp_reader *pfile)
pfile->line_table->highest_location--;
_cpp_do_file_change (pfile, reason, new_file, new_lineno, new_sysp);
+ line_table->seen_line_directive = true;
}
/* Arrange the file_change callback. pfile->line has changed to
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index e1681ea591d..ddeaf0c1954 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -386,6 +386,9 @@ struct GTY(()) line_maps {
/* The special location value that is used as spelling location for
built-in tokens. */
source_location builtin_location;
+
+ /* True if we've seen a #line or # 44 "file" directive. */
+ bool seen_line_directive;
};
/* Returns the pointer to the memory region where information about