From 789d0ee5158112e6d6508cb2eaf6eda15dd5b836 Mon Sep 17 00:00:00 2001 From: Richard Stallman Date: Tue, 25 Aug 1992 21:25:20 +0000 Subject: [PATCH] (do_pragma): Warn if `#pragma implementation "foo.h"' is invoked after "foo.h" has been included. From-SVN: r1953 --- gcc/cccp.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/gcc/cccp.c b/gcc/cccp.c index 084af358a60..7cb186a3867 100644 --- a/gcc/cccp.c +++ b/gcc/cccp.c @@ -5867,7 +5867,7 @@ do_ident (buf, limit) } /* #pragma and its argument line have already been copied to the output file. - Here just check for recognized pragmas. */ + Just check for some recognized pragmas that need validation here. */ static int do_pragma (buf, limit) @@ -5882,6 +5882,29 @@ do_pragma (buf, limit) warning ("`#pragma once' is obsolete"); do_once (); } + + if (!strncmp (buf, "implementation", 14)) { + /* Be quiet about `#pragma implementation' for a file only if it hasn't + been included yet. */ + struct file_name_list *ptr; + char *p = buf + 14, *fname, *inc_fname; + SKIP_WHITE_SPACE (p); + if (*p == '\n' || *p != '\"') + return 0; + + fname = p + 1; + if (p = (char *) strchr (fname, '\"')) + *p = '\0'; + + for (ptr = all_include_files; ptr; ptr = ptr->next) { + inc_fname = (char *) strrchr (ptr->fname, '/'); + inc_fname = inc_fname ? inc_fname + 1 : ptr->fname; + if (inc_fname && !strcmp (inc_fname, fname)) + warning ("`#pragma implementation' for \"%s\" appears after its #include", + fname); + } + } + return 0; } -- 2.30.2