Project

General

Profile

Actions

Bug #14920

open

Building source in c++ mode defines __STDC_VERSION__

Added by Maarten DB 4 months ago. Updated 4 months ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
External Bug:

Description

Building a source in c++ mode defines STDC_VERSION.
The gcc manual says STDC_VERSION is only defined when compiling in c mode.
It even explicitly says the macro is not defined in c++ mode.
See https://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html#Standard-Predefined-Macros

Reproducer

Compile the following source in c and c++ mode and run run both executables.

#include <stdio.h>
int main() {
#if defined(__cplusplus)
    printf("__cplusplus: %d\n", __cplusplus);
#else
    printf("__cplusplus: not defined\n");
#endif
#if defined(__STDC_VERSION__)
    printf("__STDC_VERSION__: %d\n", __STDC_VERSION__);
#else
    printf("__STDC_VERSION__: not defined\n");
#endif
    return 0;
}
gcc -xc main.c -o main_c
gcc -xc++ main.c -o main_cpp
./main_c
./main_cpp

Actual result

__cplusplus: not defined
__STDC_VERSION__: 201710
__cplusplus: 201703
__STDC_VERSION__: 201112

Expected result

__cplusplus: not defined
__STDC_VERSION__: 201710
__cplusplus: 201703
__STDC_VERSION__: not defined
Actions #1

Updated by Joshua M. Clulow 4 months ago

  • Description updated (diff)
Actions #2

Updated by Joshua M. Clulow 4 months ago

  • Description updated (diff)
Actions #3

Updated by Joshua M. Clulow 4 months ago

It was suggested this is related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57025

Actions

Also available in: Atom PDF