diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 17ec1fe0b946de..db8a7568a12114 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -389,6 +389,8 @@ Bug Fixes to C++ Support - Fixed a crash when clang tries to subtitute parameter pack while retaining the parameter pack. #GH63819, #GH107560 - Fix a crash when a static assert declaration has an invalid close location. (#GH108687) +- Fixed a bug in computing result type of conditional operator with omitted middle operand + (a GNU extension). (#GH15998) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 8f3e15cc9a9bb7..c232d40ca31ac6 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -8785,14 +8785,11 @@ ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc, commonExpr = result.get(); } // We usually want to apply unary conversions *before* saving, except - // in the special case of a C++ l-value conditional. - if (!(getLangOpts().CPlusPlus - && !commonExpr->isTypeDependent() - && commonExpr->getValueKind() == RHSExpr->getValueKind() - && commonExpr->isGLValue() - && commonExpr->isOrdinaryOrBitFieldObject() - && RHSExpr->isOrdinaryOrBitFieldObject() - && Context.hasSameType(commonExpr->getType(), RHSExpr->getType()))) { + // in the special case in C++ that operands have the same type. + if (!(getLangOpts().CPlusPlus && !commonExpr->isTypeDependent() && + commonExpr->isOrdinaryOrBitFieldObject() && + RHSExpr->isOrdinaryOrBitFieldObject() && + Context.hasSameType(commonExpr->getType(), RHSExpr->getType()))) { ExprResult commonRes = UsualUnaryConversions(commonExpr); if (commonRes.isInvalid()) return ExprError(); diff --git a/clang/test/SemaCXX/conditional-gnu-ext.cpp b/clang/test/SemaCXX/conditional-gnu-ext.cpp new file mode 100644 index 00000000000000..83a6fff8467863 --- /dev/null +++ b/clang/test/SemaCXX/conditional-gnu-ext.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s -fexperimental-new-constant-interpreter +// expected-no-diagnostics + +/* +FIXME: Support constexpr + +constexpr int evaluate_once(int x) { + return (++x) ? : 10; +} +static_assert(evaluate_once(0) == 1, ""); +*/ + +namespace GH15998 { + enum E { Zero, One }; + E test(E e) { + return e ? : One; + } +}