re PR c++/17577 (#pragma implementation no longer diagnoses use after file to which...
authorTom Tromey <tromey@redhat.com>
Mon, 12 Nov 2007 00:38:48 +0000 (00:38 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Mon, 12 Nov 2007 00:38:48 +0000 (00:38 +0000)
gcc/cp
PR c++/17577:
* lex.c (handle_pragma_implementation): Use cpp_included_before.
gcc/testsuite
PR c++/17577:
* g++.dg/ext/pr17577.h: New file.
* g++.dg/ext/pr17577.C: New file.
libcpp
PR c++/17557:
* include/cpplib.h (cpp_included_before): Declare.
* files.c (struct file_hash_entry) <location>: New field.
(_cpp_find_file): Initialize new field.
(make_cpp_dir): Likewise.
(cpp_included_before): New function.

From-SVN: r130093

gcc/cp/ChangeLog
gcc/cp/lex.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/pr17577.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/pr17577.h [new file with mode: 0644]
libcpp/ChangeLog
libcpp/files.c
libcpp/include/cpplib.h

index cfeea801148f97c17089e5fe06582d1454d71558..1cc38952d7cb5a1d5d6db9f3a2eed189986c149b 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-11  Tom Tromey  <tromey@redhat.com>
+
+       PR c++/17577:
+       * lex.c (handle_pragma_implementation): Use cpp_included_before.
+
 2007-11-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR c++/8570
index 3bb1bf43620a856683b29208161723f96c3e2e20..136260bef492bc8cbbc91ecd47f334b28e38f51f 100644 (file)
@@ -572,14 +572,14 @@ handle_pragma_implementation (cpp_reader* dfile ATTRIBUTE_UNUSED )
   else
     {
       filename = ggc_strdup (TREE_STRING_POINTER (fname));
-#if 0
+#ifdef USE_MAPPED_LOCATION
       /* We currently cannot give this diagnostic, as we reach this point
         only after cpplib has scanned the entire translation unit, so
         cpp_included always returns true.  A plausible fix is to compare
         the current source-location cookie with the first source-location
         cookie (if any) of the filename, but this requires completing the
         --enable-mapped-location project first.  See PR 17577.  */
-      if (cpp_included (parse_in, filename))
+      if (cpp_included_before (parse_in, filename, input_location))
        warning (0, "#pragma implementation for %qs appears after "
                 "file is included", filename);
 #endif
index 3c9a1a09891159c1e8587f904bb08235d1d3c997..b55f3c053ee7fb3a85d3c0c67cd195bce77f01eb 100644 (file)
@@ -1,3 +1,9 @@
+2007-11-11  Tom Tromey  <tromey@redhat.com>
+
+       PR c++/17577:
+       * g++.dg/ext/pr17577.h: New file.
+       * g++.dg/ext/pr17577.C: New file.
+
 2007-11-12  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR c++/8570
diff --git a/gcc/testsuite/g++.dg/ext/pr17577.C b/gcc/testsuite/g++.dg/ext/pr17577.C
new file mode 100644 (file)
index 0000000..29b1d17
--- /dev/null
@@ -0,0 +1,6 @@
+// Test for PR c++/17577.
+
+/* { dg-do compile } */
+
+#include "pr17577.h"
+#pragma implementation "pr17577.h" /* { dg-warning "appears after file" } */
diff --git a/gcc/testsuite/g++.dg/ext/pr17577.h b/gcc/testsuite/g++.dg/ext/pr17577.h
new file mode 100644 (file)
index 0000000..6ff0add
--- /dev/null
@@ -0,0 +1,2 @@
+// Test for PR c++/17577.
+#pragma interface
index c7cfa174709c3cd5dd881a5e8bc78ff1c1ab5731..4c33bd7d8d357ecf53f4cb8bd4612624f4011c5d 100644 (file)
@@ -1,3 +1,17 @@
+2007-11-11  Tom Tromey  <tromey@redhat.com>
+
+       PR c++/17557:
+       * include/cpplib.h (cpp_included_before): Declare.
+       * files.c (struct file_hash_entry) <location>: New field.
+       (_cpp_find_file): Initialize new field.
+       (make_cpp_dir): Likewise.
+       (cpp_included_before): New function.
+
+2007-11-05  Tom Tromey  <tromey@redhat.com>
+
+       * include/line-map.h (LINEMAP_POSITION_FOR_COLUMN): Wrap in
+       do-while.
+
 2007-11-01  Tom Tromey  <tromey@redhat.com>
 
        PR preprocessor/30805:
index 73f88bb3cde35748f95968c1364426fa9c831329..ae2f2945d9e58b5da32255bab26690e53a2d269a 100644 (file)
@@ -142,6 +142,7 @@ struct file_hash_entry
 {
   struct file_hash_entry *next;
   cpp_dir *start_dir;
+  source_location location;
   union
   {
     _cpp_file *file;
@@ -521,6 +522,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
   entry = new_file_hash_entry (pfile);
   entry->next = *hash_slot;
   entry->start_dir = start_dir;
+  entry->location = pfile->line_table->highest_location;
   entry->u.file = file;
   *hash_slot = entry;
 
@@ -533,6 +535,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
       entry = new_file_hash_entry (pfile);
       entry->next = *hash_slot;
       entry->start_dir = pfile->bracket_include;
+      entry->location = pfile->line_table->highest_location;
       entry->u.file = file;
       *hash_slot = entry;
     }
@@ -543,6 +546,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
       entry = new_file_hash_entry (pfile);
       entry->next = *hash_slot;
       entry->start_dir = pfile->quote_include;
+      entry->location = pfile->line_table->highest_location;
       entry->u.file = file;
       *hash_slot = entry;
     }
@@ -993,6 +997,7 @@ make_cpp_dir (cpp_reader *pfile, const char *dir_name, int sysp)
   entry = new_file_hash_entry (pfile);
   entry->next = *hash_slot;
   entry->start_dir = NULL;
+  entry->location = pfile->line_table->highest_location;
   entry->u.dir = dir;
   *hash_slot = entry;
 
@@ -1036,6 +1041,25 @@ cpp_included (cpp_reader *pfile, const char *fname)
   return entry != NULL;
 }
 
+/* Returns TRUE if a file FNAME has ever been successfully opened
+   before LOCATION.  This routine is not intended to correctly handle
+   filenames aliased by links or redundant . or .. traversals etc.  */
+bool
+cpp_included_before (cpp_reader *pfile, const char *fname,
+                    source_location location)
+{
+  struct file_hash_entry *entry;
+
+  entry = (struct file_hash_entry *)
+     htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname));
+
+  while (entry && (entry->start_dir == NULL || entry->u.file->err_no
+                  || entry->location > location))
+    entry = entry->next;
+
+  return entry != NULL;
+}
+
 /* Calculate the hash value of a file hash entry P.  */
 
 static hashval_t
index ff13cd6b532e67ae7c700d869db60633ea5e7412..01e982fbceb36ce6141c9be802e683118ec8d4e4 100644 (file)
@@ -853,6 +853,7 @@ extern unsigned char *cpp_quote_string (unsigned char *, const unsigned char *,
 
 /* In cppfiles.c */
 extern bool cpp_included (cpp_reader *, const char *);
+extern bool cpp_included_before (cpp_reader *, const char *, source_location);
 extern void cpp_make_system_header (cpp_reader *, int, int);
 extern bool cpp_push_include (cpp_reader *, const char *);
 extern void cpp_change_file (cpp_reader *, enum lc_reason, const char *);