Why can a braced-init-list not be used as an expression in a conditional operator?

Well, here’s what a note in the C++11 standard, [dcl.init.list] p1 says:

List-initialization can be used

  • as the initializer in a variable definition ([dcl.init])
  • as the initializer in a new expression ([expr.new])
  • in a return statement ([stmt.return])
  • as a function argument ([expr.call])
  • as a subscript ([expr.sub])
  • as an argument to a constructor invocation ([dcl.init], [expr.type.conv])
  • as an initializer for a non-static data member ([class.mem])
  • in a mem-initializer ([class.base.init])
  • on the right-hand side of an assignment ([expr.ass])

Since this doesn’t mention the conditional operator, your compiler is right. Also note that the conditional operator expects expressions on the both sides of : ([expr.cond]), and a braced-init-list is not an expression.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)