From 6322c7734eb75e7f57f2af85f7a53e708288fa7f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 9 Apr 2025 15:41:31 -0700 Subject: [PATCH] Don't define an unscoped enumeration out of line. (#5282) The C++ language semantics for doing so are weird and a bit broken. Under [CWG1485](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1485) this code may become invalid in the future. --- toolchain/parse/precedence.h | 75 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/toolchain/parse/precedence.h b/toolchain/parse/precedence.h index 5cd290efb9ab..4617db54fcb2 100644 --- a/toolchain/parse/precedence.h +++ b/toolchain/parse/precedence.h @@ -88,7 +88,43 @@ class PrecedenceGroup { } private: - enum PrecedenceLevel : int8_t; + enum PrecedenceLevel : int8_t { + // Sentinel representing the absence of any operator. + Highest, + // Terms. + TermPrefix, + // Numeric. + IncrementDecrement, + NumericPrefix, + Modulo, + Multiplicative, + Additive, + // Bitwise. + BitwisePrefix, + BitwiseAnd, + BitwiseOr, + BitwiseXor, + BitShift, + // Type formation. + TypePrefix, + TypePostfix, + // `where` keyword. + Where, + // Casts. + As, + // Logical. + LogicalPrefix, + Relational, + LogicalAnd, + LogicalOr, + // Conditional. + If, + // Assignment. + Assignment, + // Sentinel representing a context in which any operator can appear. + Lowest, + }; + struct OperatorPriorityTable; static const int8_t NumPrecedenceLevels; @@ -117,43 +153,6 @@ struct PrecedenceGroup::Trailing { // //////////////////////////////////////////////////////////////////////////////// -enum PrecedenceGroup::PrecedenceLevel : int8_t { - // Sentinel representing the absence of any operator. - Highest, - // Terms. - TermPrefix, - // Numeric. - IncrementDecrement, - NumericPrefix, - Modulo, - Multiplicative, - Additive, - // Bitwise. - BitwisePrefix, - BitwiseAnd, - BitwiseOr, - BitwiseXor, - BitShift, - // Type formation. - TypePrefix, - TypePostfix, - // `where` keyword. - Where, - // Casts. - As, - // Logical. - LogicalPrefix, - Relational, - LogicalAnd, - LogicalOr, - // Conditional. - If, - // Assignment. - Assignment, - // Sentinel representing a context in which any operator can appear. - Lowest, -}; - inline auto PrecedenceGroup::ForPostfixExpr() -> PrecedenceGroup { return PrecedenceGroup(Highest); }