0
  struct Box {
        Box() { puts("default"); }
        Box(Box const&) { puts("copy"); }
        Box(int, float) { puts("int, float"); }
        Box(int) { puts("int"); }
        Box(Box&&) { puts("move"); }
    }

Box box1 = {34}; // chooses Box(int) copy-list-initialization
Box box2 = 34; // chooses Box(int) copy initialization

// But if -fno-elide-constructors flag been used, 
   // box1 prints only int
   // box2 prints int and move
  • Why move constructor is not called in the case of box1 being initialized with a temporary?
  • if initializer_list constructor is provided which takes int eg( Box(std::initializer_list) {} ), braced init list always calls init list c'tor. why? using c++ 14 clang
Vegeta
  • 461
  • 2
  • 6
  • "*if initializer_list constructor is thrown which takes int*" What does that mean? Particularly "is thrown"? – Nicol Bolas Jan 24 '21 at 07:03
  • It would improve the question to post a Minimal, Reproducible Example and explain how the output differs from what you expected – M.M Jan 24 '21 at 07:04

0 Answers0