diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2787,7 +2787,9 @@ // Mimicking gcc's behavior, trigraphs are only enabled if -trigraphs // is specified, or -std is set to a conforming mode. // Trigraphs are disabled by default in c++1z onwards. - Opts.Trigraphs = !Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus17; + // For z/OS, trigraphs are enabled by default (without regard to the above). + Opts.Trigraphs = + (!Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus17) || T.isOSzOS(); Opts.Trigraphs = Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs); diff --git a/clang/test/Frontend/trigraphs.cpp b/clang/test/Frontend/trigraphs.cpp --- a/clang/test/Frontend/trigraphs.cpp +++ b/clang/test/Frontend/trigraphs.cpp @@ -4,12 +4,14 @@ // RUN: %clang_cc1 -DSTDCPP17 -std=c++1z -verify -fsyntax-only %s // RUN: %clang_cc1 -DSTDCPP17TRI -ftrigraphs -std=c++1z -verify -fsyntax-only %s // RUN: %clang_cc1 -DMSCOMPAT -fms-compatibility -std=c++11 -verify -fsyntax-only %s +// RUN: %clang_cc1 -DNOTRI -fno-trigraphs -verify -fsyntax-only %s void foo() { #if defined(NOFLAGS) || defined(STDCPP11) || defined(STDGNU11TRI) || \ - defined(STDCPP17TRI) + defined(STDCPP17TRI) || (defined(__MVS__) && !defined(NOTRI)) const char c[] = "??/n"; // expected-warning{{trigraph converted to '\' character}} -#elif defined(STDGNU11) || defined(STDCPP17) || defined(MSCOMPAT) +#elif defined(STDGNU11) || defined(STDCPP17) || defined(MSCOMPAT) || \ + defined(NOTRI) const char c[] = "??/n"; // expected-warning{{trigraph ignored}} #else #error Not handled. diff --git a/clang/test/Lexer/cxx1z-trigraphs.cpp b/clang/test/Lexer/cxx1z-trigraphs.cpp --- a/clang/test/Lexer/cxx1z-trigraphs.cpp +++ b/clang/test/Lexer/cxx1z-trigraphs.cpp @@ -1,14 +1,31 @@ // RUN: %clang_cc1 -std=c++1z %s -verify -// RUN: %clang_cc1 -std=c++1z %s -ftrigraphs -fsyntax-only 2>&1 | FileCheck --check-prefix=TRIGRAPHS %s +// RUN: %clang_cc1 -std=c++1z %s -verify -ftrigraphs -DENABLED_TRIGRAPHS=1 +// RUN: %clang_cc1 -std=c++1z %s -verify -fno-trigraphs -DENABLED_TRIGRAPHS=0 -??= define foo ; // expected-error {{}} expected-warning {{trigraph ignored}} +#ifdef __MVS__ +#ifndef ENABLED_TRIGRAPHS +#define ENABLED_TRIGRAPHS 1 +#endif +#endif -static_assert("??="[0] == '#', ""); // expected-error {{failed}} expected-warning {{trigraph ignored}} +??= define foo ; + +static_assert("??="[0] == '#', ""); // ??/ -error here; // expected-error {{}} +error here; -// Note, there is intentionally trailing whitespace two lines below. -// TRIGRAPHS: :[[@LINE+1]]:{{.*}} backslash and newline separated by space +// Note, there is intentionally trailing whitespace one line below. // ??/ -error here; // expected-error {{}} +error here; + +#if !ENABLED_TRIGRAPHS +// expected-error@11 {{}} expected-warning@11 {{trigraph ignored}} +// expected-error@13 {{failed}} expected-warning@13 {{trigraph ignored}} +// expected-error@16 {{}} +// expected-error@20 {{}} +#else +// expected-warning@11 {{trigraph converted}} +// expected-warning@13 {{trigraph converted}} +// expected-warning@19 {{backslash and newline separated by space}} +#endif