aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2021-10-07 15:28:36 -0700
committerIan Lance Taylor <iant@golang.org>2021-10-07 15:28:36 -0700
commit0b6b70a0733672600644c8df96942cda5bf86d3d (patch)
tree9a1fbd7f782c54df55ab225ed1be057e3f3b0b8a /libcpp
parenta5b5cabc91c38710adbe5c8a2b53882abe994441 (diff)
parentfba228e259dd5112851527f2dbb62c5601100985 (diff)
downloadgcc-0b6b70a0733672600644c8df96942cda5bf86d3d.zip
gcc-0b6b70a0733672600644c8df96942cda5bf86d3d.tar.gz
gcc-0b6b70a0733672600644c8df96942cda5bf86d3d.tar.bz2
Merge from trunk revision fba228e259dd5112851527f2dbb62c5601100985.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog9
-rw-r--r--libcpp/directives.c43
-rw-r--r--libcpp/init.c4
3 files changed, 52 insertions, 4 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 35f952d..3fca7fd 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,12 @@
+2021-10-06 Jakub Jelinek <jakub@redhat.com>
+
+ * init.c (lang_defaults): Implement P2334R1, enable elifdef for
+ -std=c++23 and -std=gnu++23.
+ * directives.c (_cpp_handle_directive): Support elifdef/elifndef if
+ either CPP_OPTION (pfile, elifdef) or !CPP_OPTION (pfile, std).
+ (do_elif): For older non-std modes if pedantic pedwarn about
+ #elifdef/#elifndef directives that change behavior.
+
2021-09-01 Jakub Jelinek <jakub@redhat.com>
PR c++/100977
diff --git a/libcpp/directives.c b/libcpp/directives.c
index 261a584..b4bc8b4 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -447,7 +447,11 @@ _cpp_handle_directive (cpp_reader *pfile, bool indented)
if (dname->val.node.node->is_directive)
{
dir = &dtable[dname->val.node.node->directive_index];
- if ((dir->flags & ELIFDEF) && !CPP_OPTION (pfile, elifdef))
+ if ((dir->flags & ELIFDEF)
+ && !CPP_OPTION (pfile, elifdef)
+ /* For -std=gnu* modes elifdef is supported with
+ a pedwarn if pedantic. */
+ && CPP_OPTION (pfile, std))
dir = 0;
}
}
@@ -2117,7 +2121,26 @@ do_elif (cpp_reader *pfile)
are skipped and their controlling directives are processed as
if they were in a group that is skipped." */
if (ifs->skip_elses)
- pfile->state.skipping = 1;
+ {
+ /* In older GNU standards, #elifdef/#elifndef is supported
+ as an extension, but pedwarn if -pedantic if the presence
+ of the directive would be rejected. */
+ if (pfile->directive != &dtable[T_ELIF]
+ && ! CPP_OPTION (pfile, elifdef)
+ && CPP_PEDANTIC (pfile)
+ && !pfile->state.skipping)
+ {
+ if (CPP_OPTION (pfile, cplusplus))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C++23 is a GCC extension",
+ pfile->directive->name);
+ else
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C2X is a GCC extension",
+ pfile->directive->name);
+ }
+ pfile->state.skipping = 1;
+ }
else
{
if (pfile->directive == &dtable[T_ELIF])
@@ -2139,6 +2162,22 @@ do_elif (cpp_reader *pfile)
if (pfile->cb.used)
pfile->cb.used (pfile, pfile->directive_line, node);
check_eol (pfile, false);
+ /* In older GNU standards, #elifdef/#elifndef is supported
+ as an extension, but pedwarn if -pedantic if the presence
+ of the directive would change behavior. */
+ if (! CPP_OPTION (pfile, elifdef)
+ && CPP_PEDANTIC (pfile)
+ && pfile->state.skipping != skip)
+ {
+ if (CPP_OPTION (pfile, cplusplus))
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C++23 is a GCC extension",
+ pfile->directive->name);
+ else
+ cpp_error (pfile, CPP_DL_PEDWARN,
+ "#%s before C2X is a GCC extension",
+ pfile->directive->name);
+ }
pfile->state.skipping = skip;
}
}
diff --git a/libcpp/init.c b/libcpp/init.c
index eda17a6a..5a424e2 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -122,8 +122,8 @@ static const struct lang_flags lang_defaults[] =
/* CXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0 },
/* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 },
/* CXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0 },
- /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
- /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0 },
+ /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
+ /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1 },
/* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};