[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2022-10-31 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |11.0

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2022-04-29 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #16 from Marek Polacek  ---
Fixed.

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2022-04-29 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #15 from CVS Commits  ---
The trunk branch has been updated by Marek Polacek :

https://gcc.gnu.org/g:19c62569ccf20d2744b63482a470474391d28c02

commit r13-44-g19c62569ccf20d2744b63482a470474391d28c02
Author: Marek Polacek 
Date:   Fri Apr 29 09:38:40 2022 -0400

c++: Add fixed test [PR78244]

This was finally fixed for GCC 11 by r11-434.

PR c++/78244

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/Wnarrowing20.C: New test.

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2022-03-07 Thread ppalka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Patrick Palka  changed:

   What|Removed |Added

 CC||ppalka at gcc dot gnu.org
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=57943,
   ||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=104823

--- Comment #14 from Patrick Palka  ---
Looks like the comment #11 and comment #12 testcases are fixed for GCC 11 by
r11-434.  But recently for GCC 12 we stopped diagnosing the narrowing
conversion in f5, I reported that as PR104823.

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2021-09-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Andrew Pinski  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #13 from Andrew Pinski  ---
*** Bug 102379 has been marked as a duplicate of this bug. ***

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2019-10-26 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #12 from Marek Polacek  ---
Another bit to extend the Comment 11 test:

// Test OVERLOAD in a template.
int id(int v) { return v; }
double id(double v) { return v; }

template 
auto f5(double v) -> decltype((S{id(v)}, 1)) { return 1; } // { dg-error
"narrowing conversion" }

template 
auto f6(int v) -> decltype((S{id(v)}, 1)) { return 1; }

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2019-01-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #11 from Marek Polacek  ---
What still remains to be fixed is:

// PR c++/78244
// { dg-do compile { target c++11 } }

struct S { S(int); int d; };

template 
auto f1() -> decltype(S{2.0}, void()) { } // { dg-error "narrowing conversion"
}

template 
auto f2() -> decltype(S{2.0}, 1) { return 1; } // { dg-error "narrowing
conversion" }

template 
auto f3() -> decltype(void(), S{2.0}, 1) { return 1; } // { dg-error "narrowing
conversion" }

template 
auto f4() -> decltype((S{2.0}, 1)) { return 1; } // { dg-error "narrowing
conversion" }

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2019-01-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #10 from Marek Polacek  ---
Author: mpolacek
Date: Sun Jan 27 20:19:41 2019
New Revision: 268321

URL: https://gcc.gnu.org/viewcvs?rev=268321=gcc=rev
Log:
PR c++/88815 - narrowing conversion lost in decltype.
PR c++/78244 - narrowing conversion in template not detected.
* cp-tree.h (CONSTRUCTOR_IS_DEPENDENT): New.
* pt.c (instantiation_dependent_r): Consider a CONSTRUCTOR with
CONSTRUCTOR_IS_DEPENDENT instantiation-dependent.
* semantics.c (finish_compound_literal): When the compound literal
isn't instantiation-dependent and the type isn't type-dependent,
fall back to the normal processing.  Set CONSTRUCTOR_IS_DEPENDENT.

* g++.dg/cpp0x/Wnarrowing15.C: New test.
* g++.dg/cpp0x/Wnarrowing16.C: New test.
* g++.dg/cpp0x/constexpr-decltype3.C: New test.
* g++.dg/cpp1y/Wnarrowing1.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/cpp0x/Wnarrowing15.C
trunk/gcc/testsuite/g++.dg/cpp0x/Wnarrowing16.C
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-decltype3.C
trunk/gcc/testsuite/g++.dg/cpp1y/Wnarrowing1.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/pt.c
trunk/gcc/cp/semantics.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2019-01-16 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #9 from Marek Polacek  ---
Author: mpolacek
Date: Wed Jan 16 15:58:34 2019
New Revision: 267976

URL: https://gcc.gnu.org/viewcvs?rev=267976=gcc=rev
Log:
PR c++/78244 - narrowing conversion in template not detected.
* call.c (perform_implicit_conversion_flags): Set
IMPLICIT_CONV_EXPR_BRACED_INIT.
* cp-tree.h (IMPLICIT_CONV_EXPR_BRACED_INIT): New.
* pt.c (tsubst_copy_and_build): Use it.

* g++.dg/cpp0x/Wnarrowing13.C: New test.
* g++.dg/cpp0x/Wnarrowing14.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/cpp0x/Wnarrowing13.C
trunk/gcc/testsuite/g++.dg/cpp0x/Wnarrowing14.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/pt.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-11-13 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #8 from Marek Polacek  ---
Testcase from 88012:

using Number = unsigned int;

template 
struct S {
  S() {
const Number x = {-1};
(void)x;
  }
};

int main()
{
  S<1> s;
}

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-11-13 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Marek Polacek  changed:

   What|Removed |Added

 CC||vz-gcc at zeitlins dot org

--- Comment #7 from Marek Polacek  ---
*** Bug 88012 has been marked as a duplicate of this bug. ***

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-11-13 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #6 from Jakub Jelinek  ---
When we are tsubsting this it is from fold_nondependent_expr which is called
with complain == tf_none and that is why nothing is reported.

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-08-14 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #5 from Marek Polacek  ---
And with class templates:

template
struct S {
  static const int i{1.1};
};

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-08-14 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #4 from Marek Polacek  ---
Another simple test:

template
decltype(int{1.1}) v;

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-08-14 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

--- Comment #3 from Marek Polacek  ---
Enhanced testcase (so that I don't lose it):

template 
auto f1(T) -> decltype(int{2.0}, void()) { }

template 
auto f2(T) -> decltype(int{2.0}) { return 1; }

template 
auto f3(T) -> decltype(void(), int{2.0}) { return 1; }

int
main ()
{
  f1 (0);
  f2 (0);
  f3 (0);
}

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-06-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
 CC||mpolacek at gcc dot gnu.org
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2018-06-20 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Jonathan Wakely  changed:

   What|Removed |Added

   Last reconfirmed|2016-11-08 00:00:00 |2018-6-20
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=57891

--- Comment #2 from Jonathan Wakely  ---
Closely related to PR 57891 but that relates to narrowing of a non-type
template argument, whereas this is narrowing during substitution so let's keep
it open.

[Bug c++/78244] Narrowing conversion is accepted in a function template, but it should be rejected

2016-11-08 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78244

Martin Liška  changed:

   What|Removed |Added

   Keywords||accepts-invalid
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-11-08
 CC||marxin at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Martin Liška  ---
Confirmed, all releases are affected. Clang rejects the second test-case:

$ clang++ pr78244.cpp -std=c++11
pr78244.cpp:2:31: error: type 'double' cannot be narrowed to 'int' in
initializer list [-Wc++11-narrowing]
auto f(T) -> decltype(int{0.}, void()) { }
  ^~
pr78244.cpp:2:31: note: insert an explicit cast to silence this issue
auto f(T) -> decltype(int{0.}, void()) { }
  ^~
  static_cast( )
pr78244.cpp:5:9: error: no matching function for call to 'f'
f(0);
^
pr78244.cpp:2:10: note: candidate template ignored: substitution failure [with
T = int]: type 'double' cannot be narrowed to 'int' in initializer list
auto f(T) -> decltype(int{0.}, void()) { }
 ^~~
2 errors generated.