<div class="__aliyun_email_body_block"><div  style="clear:both;"><span  style="font-family:Tahoma,Arial,STHeiti,SimSun;font-size:14.0px;color:#000000;">Recently our collegues find that gcc and clang have different behavior on the following code:</span></div><div  style="clear:both;">```</div><div  style="clear:both;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">int main() {</span><br  style="caret-color:#000000;color:#000000;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">  uint32_t a = rand();</span><br  style="caret-color:#000000;color:#000000;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">  uint32_t b = rand();</span><br  style="caret-color:#000000;color:#000000;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">  std::tuple<std::vector<int>, uint32_t, int32_t> k{{}, 0, a - b};</span><br  style="caret-color:#000000;color:#000000;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">  return std::get<1>(k);</span><br  style="caret-color:#000000;color:#000000;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:.0px;text-transform:none;white-space:normal;widows:auto;word-spacing:.0px;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">}</span></div><div  style="clear:both;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">```</span></div><div  style="clear:both;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;"><br ></span></div><div  style="clear:both;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">gcc would warn the converting from `a-b` to the third arguments of the constructor with type const int32_t& is a narrowing convering. And the clang wouldn't emit any warnings. We want to figure it out which one is right (to diagnose or not).</span></div><div  style="clear:both;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;"><br ></span></div><div  style="clear:both;"><span  style="caret-color:#000000;color:#000000;font-size:medium;font-style:normal;font-variant-caps:normal;font-weight:normal;text-align:start;text-indent:.0px;text-transform:none;text-decoration:none;float:none;display:inline;">From the standard documentation (N4849, 9.4.4 list initialization), I find the narrowing definition is:</span></div><div  style="clear:both;"><span  style="font-size:16.0px;">```</span></div><div  style="clear:both;"><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">A narrowing conversion is an implicit conversion</span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-size:16.0px;"><span  style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:16.0px;line-height:normal;font-family:Helvetica;">(7.1) </span><span  style="font-style:normal;font-weight:normal;font-size:16.0px;font-family:Helvetica;">— from a floating-point type to an integer type, or</span></span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-size:16.0px;"><span  style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:16.0px;line-height:normal;font-family:Helvetica;">(7.2) </span><span  style="font-style:normal;font-weight:normal;font-size:16.0px;font-family:Helvetica;">— from long double to double or float, or from double to float, except where the source is a constant</span></span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">expression and the actual value after conversion is within the range of values that can be represented</span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">(even if it cannot be represented exactly), or</span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-size:16.0px;"><span  style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:16.0px;line-height:normal;font-family:Helvetica;">(7.3) </span><span  style="font-style:normal;font-weight:normal;font-size:16.0px;font-family:Helvetica;">— from an integer type or unscoped enumeration type to a floating-point type, except where the source is</span></span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">a constant expression and the actual value after conversion will fit into the target type and will produce</span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">the original value when converted back to the original type, or</span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-size:16.0px;"><span  style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;line-height:normal;font-family:Helvetica;">(7.4) </span><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;">— from an integer type or unscoped enumeration type to an integer type that cannot represent all the</span></span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">values of the original type, except where the source is a constant expression whose value after integral</span></p><p  style="margin:.0px;font-variant-caps:normal;font-stretch:normal;line-height:normal;"><span  style="font-style:normal;font-weight:normal;font-family:Helvetica;font-size:16.0px;">promotions will fit into the target type.</span></p></div><div  style="clear:both;"><span  style="font-size:16.0px;">```</span></div><div  style="clear:both;"><span  style="font-size:16.0px;"><br ></span></div><div  style="clear:both;"><span  style="font-size:16.0px;">From the literal, I think that converting unsigned int to int is a narrowing while converting unsigned int to const int& is not narrowing. Since I think the reference type of an integer type is different from an integer type. </span></div><div  style="clear:both;"><span  style="font-size:16.0px;"><br ></span></div><div  style="clear:both;"><span  style="font-size:16.0px;">So I want to ask that is it a narrowing that converting a unsigned int to const int&?</span></div></div>