1

Consider a class with two std::atomic<int> members, initialized as below. I'm looking for a language lawyer answer, with references, to the question: is there any difference between the two of these syntaxes according to the C++11 standard?

class Foo {
  std::atomic<int> a   {17};  // 1.
  std::atomic<int> b = {17};  // 2.
}

My reading of [dcl.init] in the standard is that these are both list-initialization, but I'm having trouble keeping all of the relevant bits in my head and am not confident about that.

If there's no difference for std::atomic<int>, would there be for any other type?

Edit: This was marked as a dupe of another question that does answer the basic issue, but doesn't contain references in the standard. I'm looking for particular sections that define these to be equivalent, or define their differences. In particular, I can't find the exact place where the syntax for #2 is defined.

Community
  • 1
  • 1
jacobsa
  • 5,719
  • 1
  • 28
  • 60
  • `std::atomic` is not different in this regard. – Shoe Jun 19 '14 at 10:19
  • "but doesn't contain references in the standard" -- dyp's answer there does contain the references you're asking for. It mentions [over.match.list]/1 directly in the answer, and CWG 1270 contains the mention of [dcl.init.aggr]/11. –  Jun 19 '14 at 10:31
  • Well I can also mention [dcl.init]/17, which says that if the initializer is a *braced-init-list*, it's list-initialization. And that applies to both cases. Edit: Hmm it should probably be *initializer* inclusive-or (*initializer-clause* after `=`). – dyp Jun 19 '14 at 10:32
  • Interesting. This seems to be a minor defect in the Standard. [dcl.init]/17 is supposed to catch all initialization with *braced-init-lists*, yet it grammatically only applies to `X x{..}` but not to `X x = {..}` – dyp Jun 19 '14 at 10:49
  • @hvd: I missed that, sorry. Thanks! – jacobsa Jun 19 '14 at 11:04
  • @dyp: Yes, this is exactly my confusion. I guess the paragraph starting with "The form of initialization (using parentheses or =) is generally insignificant" is supposed to cover this, but it's not exactly precise. It also calls out to a section below, but not specifically, so I'm not sure which it means. – jacobsa Jun 19 '14 at 11:07
  • 1
    @dyp: I've filed an issue report about this: https://github.com/cplusplus/draft/issues/332 – jacobsa Jun 19 '14 at 11:25

0 Answers0