Re: [PATCH v2] c++: Don't quote nothrow in diagnostic

2022-09-27 Thread Marek Polacek via Gcc-patches
On Tue, Sep 27, 2022 at 10:41:29AM +0200, Richard Biener wrote: > On Mon, Sep 26, 2022 at 9:54 PM Marek Polacek wrote: > > > > On Mon, Sep 26, 2022 at 12:34:04PM -0400, Jason Merrill wrote: > > > On 9/26/22 03:50, Richard Biener wrote: > > > > On Fri, Sep 23, 2

Re: [PATCH] c++: Make __is_{,nothrow_}convertible SFINAE on access [PR107049]

2022-09-27 Thread Marek Polacek via Gcc-patches
On Tue, Sep 27, 2022 at 11:35:10AM +0100, Jonathan Wakely wrote: > Tested powerpc64le-linux. OK for trunk? > > -- >8 -- > > The is_convertible built-ins should return false if the conversion fails > an access check, not report an error. Ah, so we do need that sentinel after all. Patch looks goo

[PATCH v2] c++: Don't quote nothrow in diagnostic

2022-09-26 Thread Marek Polacek via Gcc-patches
On Mon, Sep 26, 2022 at 12:34:04PM -0400, Jason Merrill wrote: > On 9/26/22 03:50, Richard Biener wrote: > > On Fri, Sep 23, 2022 at 8:41 PM Marek Polacek via Gcc-patches > > wrote: > > > > > > In <https://gcc.gnu.org/pipermail/gcc-patches/2022-September/6020

Re: [PATCH] c++: Instantiate less when evaluating __is_convertible

2022-09-26 Thread Marek Polacek via Gcc-patches
On Mon, Sep 26, 2022 at 05:02:36PM +0100, Jonathan Wakely wrote: > On Mon, 26 Sept 2022 at 16:23, Marek Polacek wrote: > > > > Jon reported that evaluating __is_convertible in this test leads to > > instantiating char_traits::eq, which is invalid (because we > >

[PATCH v2] c++: Instantiate less when evaluating __is_convertible

2022-09-26 Thread Marek Polacek via Gcc-patches
On Mon, Sep 26, 2022 at 11:51:30AM -0400, Patrick Palka wrote: > On Mon, 26 Sep 2022, Marek Polacek via Gcc-patches wrote: > > > Jon reported that evaluating __is_convertible in this test leads to > > instantiating char_traits::eq, which is invalid (because we > > are

[PATCH] c++: Instantiate less when evaluating __is_convertible

2022-09-26 Thread Marek Polacek via Gcc-patches
Jon reported that evaluating __is_convertible in this test leads to instantiating char_traits::eq, which is invalid (because we are trying to call a member function on a char) and so we fail to compile the test. __is_convertible doesn't and shouldn't need to instantiate so much, so let's limit it

[PATCH] c++: P2513R4, char8_t Compatibility and Portability Fix [PR106656]

2022-09-23 Thread Marek Polacek via Gcc-patches
P0482R6, which added char8_t, didn't allow const char arr[] = u8"howdy"; because it said "Declarations of arrays of char may currently be initialized with UTF-8 string literals. Under this proposal, such initializations would become ill-formed." This caused too many issues, so P2513R4 alleviat

[PATCH] c++: Don't quote nothrow in diagnostic

2022-09-23 Thread Marek Polacek via Gcc-patches
In Jason noticed that we quote "nothrow" in diagnostics even though it's not a keyword in C++. Just removing the quotes didn't work because then -Wformat-diag complains, so this patch replaces it with "no-throw". Bootstrapped/

Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784]

2022-09-23 Thread Marek Polacek via Gcc-patches
On Fri, Sep 23, 2022 at 05:34:21PM +0100, Jonathan Wakely wrote: > On Fri, 23 Sept 2022 at 15:43, Jonathan Wakely wrote: > > > > On Fri, 23 Sept 2022 at 15:34, Marek Polacek wrote: > > > > > > On Thu, Sep 22, 2022 at 06:14:44PM -0400, Jason Merrill wrote: > &

Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784]

2022-09-23 Thread Marek Polacek via Gcc-patches
On Fri, Sep 23, 2022 at 11:54:53AM -0400, Jason Merrill wrote: > On 9/23/22 10:34, Marek Polacek wrote: > > On Thu, Sep 22, 2022 at 06:14:44PM -0400, Jason Merrill wrote: > > > On 9/22/22 09:39, Marek Polacek wrote: > > > > To improve compile times, the C++ librar

Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784]

2022-09-23 Thread Marek Polacek via Gcc-patches
On Fri, Sep 23, 2022 at 03:40:23PM +0100, Jonathan Wakely wrote: > On Thu, 22 Sept 2022 at 23:14, Jason Merrill wrote: > > On 9/22/22 09:39, Marek Polacek wrote: > > > This patch doesn't make libstdc++ use the new built-ins, but I had to > > > rename a class otherwi

Re: [PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784]

2022-09-23 Thread Marek Polacek via Gcc-patches
On Thu, Sep 22, 2022 at 06:14:44PM -0400, Jason Merrill wrote: > On 9/22/22 09:39, Marek Polacek wrote: > > To improve compile times, the C++ library could use compiler built-ins > > rather than implementing std::is_convertible (and _nothrow) as class > > templates. This pat

[PATCH] c++: Implement __is_{nothrow_,}convertible [PR106784]

2022-09-22 Thread Marek Polacek via Gcc-patches
To improve compile times, the C++ library could use compiler built-ins rather than implementing std::is_convertible (and _nothrow) as class templates. This patch adds the built-ins. We already have __is_constructible and __is_assignable, and the nothrow forms of those. Microsoft (and clang, for

[PATCH] c++: ICE-on-invalid with designated initializer [PR106983]

2022-09-20 Thread Marek Polacek via Gcc-patches
We ICE in the code added in r12-7117: type_build_dtor_call gets the error_mark_node because the type of 'prev' wasn't declared. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/106983 gcc/cp/ChangeLog: * typeck2.cc (split_nonconstant_init_1): Check TYPE_P. gc

Re: [PATCH] c++: Implement C++23 P2266R1, Simpler implicit move [PR101165]

2022-09-20 Thread Marek Polacek via Gcc-patches
On Mon, Sep 12, 2022 at 04:27:27PM -0400, Jason Merrill wrote: > On 9/8/22 18:54, Marek Polacek wrote: > > On Tue, Sep 06, 2022 at 10:38:12PM -0400, Jason Merrill wrote: > > > On 9/3/22 12:42, Marek Polacek wrote: > > > > This patch implements https://wg21

[PATCH v2] c++: Implement C++23 P2266R1, Simpler implicit move [PR101165]

2022-09-20 Thread Marek Polacek via Gcc-patches
On Tue, Sep 06, 2022 at 10:38:12PM -0400, Jason Merrill wrote: > On 9/3/22 12:42, Marek Polacek wrote: > > This patch implements https://wg21.link/p2266, which, once again, > > changes the implicit move rules. Here's a brief summary of various > > changes in t

[PATCH] c: Stray inform note with -Waddress [PR106947]

2022-09-19 Thread Marek Polacek via Gcc-patches
A trivial fix for maybe_warn_for_null_address where we print an inform note without first checking the return value of a warning call. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12? PR c/106947 gcc/c/ChangeLog: * c-typeck.cc (maybe_warn_for_null_address): Don't

Re: [PATCH] c++: Implement C++23 P2266R1, Simpler implicit move [PR101165]

2022-09-08 Thread Marek Polacek via Gcc-patches
On Tue, Sep 06, 2022 at 10:38:12PM -0400, Jason Merrill wrote: > On 9/3/22 12:42, Marek Polacek wrote: > > This patch implements https://wg21.link/p2266, which, once again, > > changes the implicit move rules. Here's a brief summary of various > > changes in t

[PATCH] c++: Implement C++23 P2266R1, Simpler implicit move [PR101165]

2022-09-03 Thread Marek Polacek via Gcc-patches
This patch implements https://wg21.link/p2266, which, once again, changes the implicit move rules. Here's a brief summary of various changes in this area: r125211: Introduced moving from certain lvalues when returning them r171071: CWG 1148, enable move from value parameter on return r212099: CWG

[pushed] c++: Remove unused declaration

2022-09-01 Thread Marek Polacek via Gcc-patches
This declaration was added in r260905 but the function was never defined. Tested x86_64-pc-linux-gnu, applying to trunk. gcc/cp/ChangeLog: * cp-tree.h (maybe_strip_ref_conversion): Remove. --- gcc/cp/cp-tree.h | 1 - 1 file changed, 1 deletion(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/

Re: [PATCH] c/c++: new warning: -Wxor-used-as-pow [PR90885]

2022-08-30 Thread Marek Polacek via Gcc-patches
This looks good to me, one thing though: On Thu, Aug 11, 2022 at 09:38:12PM -0400, David Malcolm via Gcc-patches wrote: > --- a/gcc/c-family/c.opt > +++ b/gcc/c-family/c.opt > @@ -1439,6 +1439,10 @@ Wwrite-strings > C ObjC C++ ObjC++ Var(warn_write_strings) Warning > In C++, nonzero means warn a

Re: -Wformat-overflow handling for %b and %B directives in C2X standard

2022-08-30 Thread Marek Polacek via Gcc-patches
On Mon, Aug 15, 2022 at 07:42:39PM +0300, Frolov Daniil wrote: > вт, 12 апр. 2022 г. в 00:56, Marek Polacek : > > > > > On Thu, Apr 07, 2022 at 02:10:48AM +0500, Frolov Daniil wrote: > > > Hello! Thanks for your feedback. I've tried to take into account your >

Re: C++: add -std={c,gnu}++{current,future}

2022-08-30 Thread Marek Polacek via Gcc-patches
On Tue, Aug 30, 2022 at 09:22:14AM -0400, Jason Merrill via Gcc-patches wrote: > On 7/13/22 15:29, Nathan Sidwell wrote: > > Inspired by a user question.  Jason, thoughts? > > > > Since C++ is such a moving target, Microsoft have /std:c++latest > > (AFAICT clang does not), to select the currently

Re: C++: add -std={c,gnu}++{current,future}

2022-08-30 Thread Marek Polacek via Gcc-patches
On Wed, Jul 13, 2022 at 03:29:04PM -0400, Nathan Sidwell via Gcc-patches wrote: > Inspired by a user question. Jason, thoughts? FWIW, this makes sense. I mean, how could I be against a patch quoting Macbeth?! > Since C++ is such a moving target, Microsoft have /std:c++latest > (AFAICT clang do

[PATCH] c++: __has_builtin gives the wrong answer [PR106759]

2022-08-29 Thread Marek Polacek via Gcc-patches
We've supported __is_nothrow_constructible since r11-4386, but names_builtin_p didn't know about it, so it gave the wrong answer for #if __has_builtin(__is_nothrow_constructible) ... #endif I've tested all C++-only built-ins and only two were missing. Bootstrapped/regtested on x86_64-pc-linux-

[PATCH v2] c++: Fix C++11 attribute propagation [PR106712]

2022-08-29 Thread Marek Polacek via Gcc-patches
On Mon, Aug 29, 2022 at 01:32:29PM -0400, Jason Merrill wrote: > On 8/26/22 19:01, Marek Polacek wrote: > > When we have > > > >[[noreturn]] int fn1 [[nodiscard]](), fn2(); > > > > "noreturn" should apply to both fn1 and fn2 but "nodisca

[PATCH] c++: Fix C++11 attribute propagation [PR106712]

2022-08-26 Thread Marek Polacek via Gcc-patches
When we have [[noreturn]] int fn1 [[nodiscard]](), fn2(); "noreturn" should apply to both fn1 and fn2 but "nodiscard" only to fn1: [dcl.pre]/3: "The attribute-specifier-seq appertains to each of the entities declared by the declarators of the init-declarator-list." [dcl.spec.general]: "The attr

[PATCH v5] c++: Implement -Wself-move warning [PR81159]

2022-08-26 Thread Marek Polacek via Gcc-patches
On Thu, Aug 25, 2022 at 08:52:58PM -0400, Jason Merrill wrote: > On 8/25/22 17:49, Marek Polacek wrote: > > On Thu, Aug 25, 2022 at 09:25:43AM -0400, Jason Merrill wrote: > > > On 8/24/22 17:30, Marek Polacek wrote: > > > > On Tue, Aug 23, 2022 at 05:27:0

Re: [PATCH v3] c: Implement C23 nullptr (N3042)

2022-08-25 Thread Marek Polacek via Gcc-patches
On Thu, Aug 25, 2022 at 09:12:07PM +, Joseph Myers wrote: > On Thu, 25 Aug 2022, Marek Polacek via Gcc-patches wrote: > > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > This version is OK. Thanks a lot. I've gone ahead and updated GCC 1

Re: [PATCH v4] c++: Implement -Wself-move warning [PR81159]

2022-08-25 Thread Marek Polacek via Gcc-patches
On Thu, Aug 25, 2022 at 09:25:43AM -0400, Jason Merrill wrote: > On 8/24/22 17:30, Marek Polacek wrote: > > On Tue, Aug 23, 2022 at 05:27:00PM -0400, Jason Merrill wrote: > > > On 8/23/22 09:39, Marek Polacek wrote: > > > > + tree arg = CALL_EXPR_ARG (fn,

[PATCH v3] c: Implement C23 nullptr (N3042)

2022-08-25 Thread Marek Polacek via Gcc-patches
On Thu, Aug 25, 2022 at 05:28:09PM +, Joseph Myers wrote: > On Wed, 24 Aug 2022, Marek Polacek via Gcc-patches wrote: > > > Ah, okay. I had just copied what we do in C++ in null_ptr_cst_p and the > > rest of the patch worked under that assumption. I've added some

Re: [PATCH v4] c++: Implement -Wself-move warning [PR81159]

2022-08-24 Thread Marek Polacek via Gcc-patches
On Tue, Aug 23, 2022 at 05:27:00PM -0400, Jason Merrill wrote: > On 8/23/22 09:39, Marek Polacek wrote: > > + tree arg = CALL_EXPR_ARG (fn, 0); > > + extract_op (arg); > > + if (TREE_CODE (arg) == ADDR_EXPR) > > +arg = TREE_OPERAND (arg, 0); > > + tree t

Re: [PATCH] c: Implement C23 nullptr (N3042)

2022-08-24 Thread Marek Polacek via Gcc-patches
On Mon, Aug 15, 2022 at 04:03:13PM -0400, Jason Merrill wrote: > On 8/13/22 14:35, Marek Polacek wrote: > > This patch implements the C23 nullptr literal: > > <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3042.htm>, which is > > intended to replace the problemat

[PATCH v2] c: Implement C23 nullptr (N3042)

2022-08-24 Thread Marek Polacek via Gcc-patches
On Mon, Aug 15, 2022 at 05:48:34PM +, Joseph Myers wrote: > On Sat, 13 Aug 2022, Marek Polacek via Gcc-patches wrote: > > > This patch also defines nullptr_t in . I'm uncertain about > > the __STDC_VERSION__ version I should be checking. Also, I'm

[PATCH v4] c++: Implement -Wself-move warning [PR81159]

2022-08-23 Thread Marek Polacek via Gcc-patches
On Sat, Aug 20, 2022 at 05:31:52PM -0400, Jason Merrill wrote: > On 8/19/22 15:34, Marek Polacek wrote: > > On Thu, Aug 18, 2022 at 08:33:47PM -0400, Jason Merrill wrote: > > > On 8/18/22 13:19, Marek Polacek wrote: > > > > On Mon, Aug 15, 2022 at 03:54:0

[PATCH] c++: Quash bogus -Wredundant-move warning

2022-08-22 Thread Marek Polacek via Gcc-patches
This patch fixes a pretty stoopid thinko. When I added code to warn about pessimizing std::move in initializations like T t{std::move(T())}; I also added code to unwrap the expression from { }. But when we have return {std::move(t)}; we cannot warn about a redundant std::move because the

Re: [PATCH] c++: Extend -Wpessimizing-move to other contexts

2022-08-22 Thread Marek Polacek via Gcc-patches
On Mon, Aug 22, 2022 at 01:48:34PM +0200, Stephan Bergmann wrote: > On 16/08/2022 14:27, Marek Polacek via Gcc-patches wrote: > > Ping. (The other std::move patches depend on this one.) > > <https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8d22c7cb8b1a6f9b67c54a798dd5504244614e

[PATCH v2] testsuite: Add test for r11-4123

2022-08-22 Thread Marek Polacek via Gcc-patches
On Mon, Aug 22, 2022 at 10:16:23AM -0700, Andrew Pinski wrote: > On Mon, Aug 22, 2022 at 9:58 AM Marek Polacek via Gcc-patches > wrote: > > > > r11-4123 came without a test but I happened upon a nice test case that > > got fixed by that revision. So I think it'd be

[PATCH] testsuite: Add test for r11-4123

2022-08-22 Thread Marek Polacek via Gcc-patches
r11-4123 came without a test but I happened upon a nice test case that got fixed by that revision. So I think it'd be good to add it. The ICE was: phi-1.C: In constructor 'ElementManager::ElementManager()': phi-1.C:28:1: error: missing definition 28 | ElementManager::ElementManager() : array_

[PATCH v3] c++: Implement -Wself-move warning [PR81159]

2022-08-19 Thread Marek Polacek via Gcc-patches
On Thu, Aug 18, 2022 at 08:33:47PM -0400, Jason Merrill wrote: > On 8/18/22 13:19, Marek Polacek wrote: > > On Mon, Aug 15, 2022 at 03:54:05PM -0400, Jason Merrill wrote: > > > On 8/9/22 09:37, Marek Polacek wrote: > > > > + /* We're looking for *std::move

[PATCH v2] c++: Implement -Wself-move warning [PR81159]

2022-08-18 Thread Marek Polacek via Gcc-patches
On Mon, Aug 15, 2022 at 03:54:05PM -0400, Jason Merrill wrote: > On 8/9/22 09:37, Marek Polacek wrote: > > + /* We're looking for *std::move ((T &) &arg), or > > + *std::move ((T &) (T *) r) if the argument it a reference. */ > > + if (!REFEREN

[pushed] c++: Add new std::move test [PR67906]

2022-08-17 Thread Marek Polacek via Gcc-patches
As discussed in 67906, let's make sure we don't warn about a std::move when initializing when there's a T(const T&&) ctor. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/67906 gcc/testsuite/ChangeLog: * g++.dg/cpp0x/Wredundant-move11.C: New test. --- .../g++.dg/cpp0x/Wre

Re: [PATCH v2] c++: Extend -Wredundant-move for const-qual objects [PR90428]

2022-08-17 Thread Marek Polacek via Gcc-patches
On Mon, Aug 15, 2022 at 03:43:38PM -0400, Jason Merrill wrote: > On 8/8/22 13:27, Marek Polacek wrote: > > This is to warn about this: > > > > T f5(const T t) > > { > >return std::move(t); // { dg-warning "redundant move" } > > } > >

Re: add more C++ name hints

2022-08-17 Thread Marek Polacek via Gcc-patches
On Fri, Aug 05, 2022 at 09:35:33PM +0200, Ulrich Drepper via Gcc-patches wrote: > How about adding a few more names from the std namespace to get appropriate > hints? This patch compiles and the appropriate messages are printed. Is > there a problem with just adding more or even at some point all

Re: [PATCH] c++: Extend -Wpessimizing-move to other contexts

2022-08-16 Thread Marek Polacek via Gcc-patches
On Tue, Aug 16, 2022 at 03:23:18PM -0400, Jason Merrill wrote: > On 8/2/22 16:04, Marek Polacek wrote: > > In my recent patch which enhanced -Wpessimizing-move so that it warns > > about class prvalues too I said that I'd like to extend it so that it > > warns in more

[wwwdocs] Add C++23 papers approved by WG21 at the July plenary

2022-08-16 Thread Marek Polacek via Gcc-patches
We have a lot of new papers to implement. I've also opened PRs for them. Pushed. commit c6f8ab1adad76d2b43f6cbdacd84202131ae1e5c Author: Marek Polacek Date: Tue Aug 16 13:39:34 2022 -0400 cxx-status: Add C++23 papers approved by WG21 at the July plenary diff --git a/htdocs/project

[wwwdocs] Update C++ DR table from Core Language Issue TOC, Revision 109

2022-08-16 Thread Marek Polacek via Gcc-patches
A lot of updates this time. Pushed. commit 0a423169f0abf14b765493d7b11b790d847494e8 Author: Marek Polacek Date: Tue Aug 16 11:32:24 2022 -0400 cxx-dr-status: Update from C++ Core Language Issue TOC, Revision 109 diff --git a/htdocs/projects/cxx-dr-status.html b/htdocs/projects/cxx-dr

Re: [PATCH] c++: Extend -Wpessimizing-move to other contexts

2022-08-16 Thread Marek Polacek via Gcc-patches
Ping. (The other std::move patches depend on this one.) (can_do_rvo_p is renamed to can_elide_copy_prvalue_p in the PR90428 patch.) On Tue, Aug 02, 2022 at 07:04:47PM -0400, Marek Polacek via Gcc-patches wrote: > In my recent patch which enhanced -Wpessimizing-move so that it warns >

Re: [PATCH] c++: Implement P2327R1 - De-deprecating volatile compound operations

2022-08-15 Thread Marek Polacek via Gcc-patches
On Mon, Aug 15, 2022 at 12:31:10PM +0200, Jakub Jelinek wrote: > Hi! > > From what I can see, this has been voted in as a DR and as it means > we warn less often than before in -std={gnu,c}++2{0,3} modes or with > -Wvolatile, I wonder if it shouldn't be backported to affected release > branches as

[PATCH] c: Implement C23 nullptr (N3042)

2022-08-13 Thread Marek Polacek via Gcc-patches
This patch implements the C23 nullptr literal: , which is intended to replace the problematic definition of NULL which might be either of integer type or void*. Since C++ has had nullptr for over a decade now, it was relatively easy to ju

[PATCH] c++: Implement -Wself-move warning [PR81159]

2022-08-09 Thread Marek Polacek via Gcc-patches
About 5 years ago we got a request to implement -Wself-move, which warns about useless moves like this: int x; x = std::move (x); This patch implements that warning. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/81159 gcc/c-family/ChangeLog: * c.opt (

Re: [PATCH v2] c++: Extend -Wredundant-move for const-qual objects [PR90428]

2022-08-09 Thread Marek Polacek via Gcc-patches
On Mon, Aug 08, 2022 at 04:27:10PM -0400, Marek Polacek wrote: > + /* Also try to warn about redundant std::move in code such as > + T f (const T& t) > + { > + return std::move(t); > + } > +for which EXPR will be something like > + *std::move (

[PATCH v2] c++: Extend -Wredundant-move for const-qual objects [PR90428]

2022-08-08 Thread Marek Polacek via Gcc-patches
On Sat, Aug 06, 2022 at 03:58:13PM -0800, Jason Merrill wrote: > On 8/6/22 11:13, Marek Polacek wrote: > > In this PR, Jon suggested extending the -Wredundant-move warning > > to warn when the user is moving a const object as in: > > > >struct T { };

[PATCH v2] c++: Tweak for -Wpessimizing-move in templates [PR89780]

2022-08-08 Thread Marek Polacek via Gcc-patches
On Sat, Aug 06, 2022 at 04:02:13PM -0700, Jason Merrill wrote: > On 8/4/22 11:46, Marek Polacek wrote: > > In my previous patches I've been extending our std::move warnings, > > but this tweak actually dials it down a little bit. As reported in > > bug 89780, it&#x

[PATCH v2] c++: Extend -Wpessimizing-move for class prvalues [PR106276]

2022-08-08 Thread Marek Polacek via Gcc-patches
On Sat, Aug 06, 2022 at 04:07:54PM -0700, Jason Merrill wrote: > On 8/6/22 15:49, Jason Merrill wrote: > > On 7/27/22 17:14, Marek Polacek wrote: > > > We already have a warning that warns about pessimizing std::move > > > in a return statement, when it prevents the

[PATCH v2] c-family: Honor -Wno-init-self for cv-qual vars [PR102633]

2022-08-08 Thread Marek Polacek via Gcc-patches
On Sat, Aug 06, 2022 at 03:29:05PM -0700, Jason Merrill wrote: > On 7/26/22 14:31, Marek Polacek wrote: > > On Tue, Jul 26, 2022 at 04:24:18PM -0400, Jason Merrill wrote: > > > On 7/26/22 15:03, Marek Polacek wrote: > > > > Since r11-5188-g32934a4f45a721, we

[PATCH] c++: Extend -Wredundant-move for const-qual objects [PR90428]

2022-08-06 Thread Marek Polacek via Gcc-patches
In this PR, Jon suggested extending the -Wredundant-move warning to warn when the user is moving a const object as in: struct T { }; T f(const T& t) { return std::move(t); } where the std::move is redundant, because T does not have a T(const T&&) constructor (which is very unlikely).

[PATCH] c++: Tweak for -Wpessimizing-move in templates [PR89780]

2022-08-04 Thread Marek Polacek via Gcc-patches
In my previous patches I've been extending our std::move warnings, but this tweak actually dials it down a little bit. As reported in bug 89780, it's questionable to warn about expressions in templates that were type-dependent, but aren't anymore because we're instantiating the template. As in,

[PATCH] c++: Extend -Wpessimizing-move to other contexts

2022-08-02 Thread Marek Polacek via Gcc-patches
In my recent patch which enhanced -Wpessimizing-move so that it warns about class prvalues too I said that I'd like to extend it so that it warns in more contexts where a std::move can prevent copy elision, such as: T t = std::move(T()); T t(std::move(T())); T t{std::move(T())}; T t = {std

Re: How to check -std=c89 or -std=gnu89 is set in C FE?

2022-08-02 Thread Marek Polacek via Gcc-patches
On Tue, Aug 02, 2022 at 04:19:56PM +, Qing Zhao via Gcc-patches wrote: > Hi, Joseph, > > When -std=c89 or -std=gnu89 present in the command line, in C FE, which flags > should be > checked to decide it’s -std=c89 or -std=gnu89? You should be able to check flag_iso and related. Marek

[PATCH] c++: Extend -Wpessimizing-move for class prvalues [PR106276]

2022-07-27 Thread Marek Polacek via Gcc-patches
We already have a warning that warns about pessimizing std::move in a return statement, when it prevents the NRVO: T fn() { T t; return std::move (t); // warning \o/ } However, the warning doesn't warn when what we are returning is a class prvalue, that is, when std::move prevents t

Re: [PATCH] c-family: Honor -Wno-init-self for cv-qual vars [PR102633]

2022-07-27 Thread Marek Polacek via Gcc-patches
On Wed, Jul 27, 2022 at 06:41:09AM +, Richard Biener via Gcc-patches wrote: > On Tue, 26 Jul 2022, Marek Polacek wrote: > > > Since r11-5188-g32934a4f45a721, we drop qualifiers during l-to-r > > conversion by creating a NOP_EXPR. For e.g. > > > > const int i

Re: [PATCH] c-family: Honor -Wno-init-self for cv-qual vars [PR102633]

2022-07-26 Thread Marek Polacek via Gcc-patches
On Tue, Jul 26, 2022 at 04:24:18PM -0400, Jason Merrill wrote: > On 7/26/22 15:03, Marek Polacek wrote: > > Since r11-5188-g32934a4f45a721, we drop qualifiers during l-to-r > > conversion by creating a NOP_EXPR. For e.g. > > > >const int i = i; > > > &

[PATCH] c-family: Honor -Wno-init-self for cv-qual vars [PR102633]

2022-07-26 Thread Marek Polacek via Gcc-patches
Since r11-5188-g32934a4f45a721, we drop qualifiers during l-to-r conversion by creating a NOP_EXPR. For e.g. const int i = i; that means that the DECL_INITIAL is '(int) i' and not 'i' anymore. Consequently, we don't suppress_warning here: 711 case DECL_EXPR: 715 if (VAR_P (DECL_EXPR

[v2 PATCH] c++: ICE with erroneous template redeclaration [PR106311]

2022-07-25 Thread Marek Polacek via Gcc-patches
On Fri, Jul 22, 2022 at 05:21:58PM -0400, Jason Merrill wrote: > On 7/15/22 11:29, Marek Polacek wrote: > > Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens > > to be error_mark_node in this ill-formed test. I kept running into this > > while reducing

Re: [PATCH] c++: ICE with erroneous template redeclaration [PR106311]

2022-07-22 Thread Marek Polacek via Gcc-patches
Ping. On Fri, Jul 15, 2022 at 11:29:20AM -0400, Marek Polacek via Gcc-patches wrote: > Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens > to be error_mark_node in this ill-formed test. I kept running into this > while reducing code, so it'd be good to

Re: [pushed] match.pd: Add new abs pattern [PR94920]

2022-07-21 Thread Marek Polacek via Gcc-patches
On Thu, Jul 21, 2022 at 05:28:34PM -0400, Sam Feifer via Gcc-patches wrote: > This patch is intended to fix a missed optimization in match.pd. It optimizes > (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) to just abs(x). Additionally, the > pattern (x <= 0 ? -x : 0) now gets optimized to max(-x, 0), which

Re: [PATCH] c++: Enable __has_builtin for new reference binding built-ins

2022-07-19 Thread Marek Polacek via Gcc-patches
On Tue, Jul 19, 2022 at 02:11:02PM +0100, Jonathan Wakely wrote: > Tested x86_64-linux, OK for trunk? > > -- >8 -- > > The new built-ins need to be detectable using __has_builtin, and the > library should use that to check for them. > > This fixes an error with Clang when C++23 is enabled. LGTM

Re: [PATCH] c++: Add __reference_con{struc,ver}ts_from_temporary [PR104477]

2022-07-15 Thread Marek Polacek via Gcc-patches
On Fri, Jul 15, 2022 at 10:59:41PM +0300, Ville Voutilainen wrote: > Well, is_xible is not is_xible_p because it doesn't need to be both is_* > and *_p. But xes_from_temporary is less obviously a question, so > xes_from_temporary_p would imho be a better name. Yeah, I guess so. But I've already p

Re: [PATCH] c++: Add __reference_con{struc,ver}ts_from_temporary [PR104477]

2022-07-15 Thread Marek Polacek via Gcc-patches
On Thu, Jul 14, 2022 at 11:48:51PM -0400, Jason Merrill wrote: > On 7/14/22 13:43, Marek Polacek wrote: > > On Tue, Jul 12, 2022 at 04:15:00PM -0400, Jason Merrill wrote: > > > On 7/12/22 16:10, Jason Merrill wrote: > > > > On 7/8/22 13:41, Marek Polacek wrote: >

[PATCH] c++: ICE with erroneous template redeclaration [PR106311]

2022-07-15 Thread Marek Polacek via Gcc-patches
Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens to be error_mark_node in this ill-formed test. I kept running into this while reducing code, so it'd be good to have it fixed. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/106311 gcc/cp/Change

Re: [PATCH] c++: Add __reference_con{struc,ver}ts_from_temporary [PR104477]

2022-07-14 Thread Marek Polacek via Gcc-patches
On Tue, Jul 12, 2022 at 04:15:00PM -0400, Jason Merrill wrote: > On 7/12/22 16:10, Jason Merrill wrote: > > On 7/8/22 13:41, Marek Polacek wrote: > > > This patch implements C++23 P2255R2, which adds two new type traits to > > > detect reference binding to a temporary. 

[PATCH v3] c++: Add __reference_con{struc,ver}ts_from_temporary [PR104477]

2022-07-14 Thread Marek Polacek via Gcc-patches
On Tue, Jul 12, 2022 at 04:10:08PM -0400, Jason Merrill wrote: > On 7/8/22 13:41, Marek Polacek wrote: > > +bool > > +reference_from_temporary (tree to, tree from, bool direct_init_p) > > +{ > > + /* Check is_reference. */ > > + if (!TYPE_REF_P (to)) >

[pushed] libcpp: Avoid pessimizing std::move [PR106272]

2022-07-13 Thread Marek Polacek via Gcc-patches
std::move in a return statement can prevent the NRVO: PR106272 reports that we have two such cases in class label_text's member functions. We have -Wpessimizing-move that's supposed to detect problematic std::m

[PATCH v2] c++: Add __reference_con{struc,ver}ts_from_temporary [PR104477]

2022-07-12 Thread Marek Polacek via Gcc-patches
On Mon, Jul 11, 2022 at 11:19:19AM +0100, Jonathan Wakely wrote: > On Fri, 8 Jul 2022 at 18:41, Marek Polacek wrote: > > The patch also adds the relevant class and variable templates to > > . > > > + template > +struct reference_constructs_from_temp > orary &

[PATCH] c++: Add __reference_con{struc, ver}ts_from_temporary [PR104477]

2022-07-08 Thread Marek Polacek via Gcc-patches
This patch implements C++23 P2255R2, which adds two new type traits to detect reference binding to a temporary. They can be used to detect code like std::tuple t("meow"); which is incorrect because it always creates a dangling reference, because the std::string temporary is created inside the

Re: [PATCH] c++: Define built-in for std::tuple_element [PR100157]

2022-07-07 Thread Marek Polacek via Gcc-patches
On Thu, Jul 07, 2022 at 06:14:36PM +0100, Jonathan Wakely wrote: > This adds a new built-in to replace the recursive class template > instantiations done by traits such as std::tuple_element and > std::variant_alternative. The purpose is to select the Nth type from a > list of types, e.g. __builtin

[PATCH] c-family: Prevent -Wformat warnings with u8 strings [PR105626]

2022-07-05 Thread Marek Polacek via Gcc-patches
The thread seems to have concluded that -Wformat shouldn't warn about printf((const char*) u8"test %d\n", 1); saying "format string is not an array of type 'char'". This code is not an aliasing violation, and there are no I/O functions f

Re: [PATCH] c-family: Add names to diagnostics for known headers

2022-07-05 Thread Marek Polacek via Gcc-patches
On Mon, Jul 04, 2022 at 05:25:42PM +0100, Jonathan Wakely wrote: > On Thu, 30 Jun 2022 at 16:15, Marek Polacek wrote: > > > > On Thu, Jun 30, 2022 at 04:11:42PM +0100, Jonathan Wakely via Gcc-patches > > wrote: > > > I recently changed to no longer include an u

Re: [PATCH] c-family: Add names to diagnostics for known headers

2022-06-30 Thread Marek Polacek via Gcc-patches
On Thu, Jun 30, 2022 at 04:11:42PM +0100, Jonathan Wakely via Gcc-patches wrote: > I recently changed to no longer include an unnecessary header, > which meant it no longer includes , which means it no longer > includes . This resulted in some build failures: > https://issues.apache.org/jira/brows

[PATCH] c++: warn about using keywords as identifiers [PR106111]

2022-06-29 Thread Marek Polacek via Gcc-patches
In C++03, -Wc++11-compat should warn about int constexpr; since 'constexpr' is a keyword in C++11. Jonathan reports that we don't emit a similar warning for 'alignas' or 'alignof', and, as I found out, 'thread_local'. Similarly, we don't warn for most C++20 keywords. That happens because RID

[pushed] c++: Add fixed test [PR89197]

2022-06-27 Thread Marek Polacek via Gcc-patches
Fixed since bug 97899 was fixed. PR c++/89197 gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist130.C: New test. --- gcc/testsuite/g++.dg/cpp0x/initlist130.C | 5 + 1 file changed, 5 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist130.C diff --git a/gcc/t

[PATCH v2] c++: fix broken copy elision with nested TARGET_EXPRs [PR105550]

2022-06-24 Thread Marek Polacek via Gcc-patches
On Thu, Jun 02, 2022 at 05:08:54PM -0400, Jason Merrill wrote: > On 5/26/22 11:01, Marek Polacek wrote: > > In this problem, we are failing to properly perform copy elision with > > a conditional operator, so this: > > > >constexpr A a = true ? A{}

Re: [PATCH] c: Extend the -Wpadded message with actual padding size

2022-06-17 Thread Marek Polacek via Gcc-patches
On Thu, Jun 16, 2022 at 09:37:32PM +0200, Vit Kabele wrote: > When the compiler warns about padding struct to alignment boundary, it > now also informs the user about the size of the alignment that needs to > be added to get rid of the warning. > > This removes the need of using pahole or similar

[PATCH] c++: Allow mixing GNU/std-style attributes [PR69585]

2022-06-03 Thread Marek Polacek via Gcc-patches
cp_parser_attributes_opt doesn't accept GNU attributes followed by [[]] attributes and vice versa; only a sequence of attributes of the same kind. That causes grief for code like: struct __attribute__ ((may_alias)) alignas (2) struct S { }; or #define EXPORT __attribute__((visibility("defau

Re: [PATCH] c++: cv-quals of dummy obj for non-dep memfn call [PR105637]

2022-06-03 Thread Marek Polacek via Gcc-patches
On Fri, Jun 03, 2022 at 11:16:26AM -0400, Jason Merrill via Gcc-patches wrote: > On 6/3/22 11:04, Patrick Palka wrote: > > > > @@ -4319,15 +4319,32 @@ maybe_dummy_object (tree type, tree* binfop) > > > > if (binfop) > > > >*binfop = binfo; > > > >- if (current_class_ref > > > > -

Re: [PATCH] c++: ICE with template NEW_EXPR [PR105803]

2022-06-02 Thread Marek Polacek via Gcc-patches
On Thu, Jun 02, 2022 at 04:26:27PM -0400, Jason Merrill wrote: > On 6/2/22 16:10, Marek Polacek wrote: > > index 1346a1d4c10..2bbd8785627 100644 > > --- a/gcc/cp/constexpr.cc > > +++ b/gcc/cp/constexpr.cc > > @@ -9039,10 +9039,18 @@ potential_constant_expression_1 (

Re: [PATCH] c++: ICE with template NEW_EXPR [PR105803]

2022-06-02 Thread Marek Polacek via Gcc-patches
On Thu, Jun 02, 2022 at 03:42:15PM -0400, Jason Merrill wrote: > On 6/2/22 10:03, Marek Polacek wrote: > > On Thu, Jun 02, 2022 at 08:42:36AM -0400, Patrick Palka wrote: > > > On Wed, 1 Jun 2022, Marek Polacek via Gcc-patches wrote: > > > > > > > Here we I

Re: [PATCH] c++: ICE with template NEW_EXPR [PR105803]

2022-06-02 Thread Marek Polacek via Gcc-patches
On Thu, Jun 02, 2022 at 08:42:36AM -0400, Patrick Palka wrote: > On Wed, 1 Jun 2022, Marek Polacek via Gcc-patches wrote: > > > Here we ICE because value_dependent_expression_p gets a NEW_EXPR > > whose operand is a type, and we go to the default case which just > > calls

[PATCH] c++: ICE with template NEW_EXPR [PR105803]

2022-06-01 Thread Marek Polacek via Gcc-patches
Here we ICE because value_dependent_expression_p gets a NEW_EXPR whose operand is a type, and we go to the default case which just calls v_d_e_p on each operand of the NEW_EXPR. Since one of them is a type, we crash on the new assert in t_d_e_p. t_d_e_p has code to handle {,VEC_}NEW_EXPR, which a

Re: [PATCH] c++: Add !TYPE_P assert to type_dependent_expression_p [PR99080]

2022-05-27 Thread Marek Polacek via Gcc-patches
On Fri, May 27, 2022 at 11:52:12AM -0400, Jason Merrill wrote: > On 5/26/22 20:33, Marek Polacek wrote: > > As discussed here: > > <https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564629.html>, > > type_dependent_expression_p should not be called with a type ar

[PATCH] c++: Fix ICE with -Wmismatched-tags [PR105725]

2022-05-27 Thread Marek Polacek via Gcc-patches
Here we ICE with -Wmismatched-tags on something like template bool B>>; Specifically, the "class T::foo" bit. There, class_decl_loc_t::add gets a TYPENAME_TYPE as TYPE, rather than a class/union type, so checking TYPE_BEING_DEFINED will crash. I think it's OK to allow a TYPENAME_TYPE to sl

[PATCH] c-family: fix attribute constructor ICE [PR90658]

2022-05-26 Thread Marek Polacek via Gcc-patches
Here the C compiler crashes because a FUNCTION_DECL got into get_priority -> default_conversion, and the C FE's version of d_c specifically asserts that it doesn't get a FUNCTION_DECL. All uses of default_conversion in c-attribs.cc are guarded by != IDENTIFIER_NODE && != FUNCTION_DECL, but get_pri

[PATCH] c++: Add !TYPE_P assert to type_dependent_expression_p [PR99080]

2022-05-26 Thread Marek Polacek via Gcc-patches
As discussed here: , type_dependent_expression_p should not be called with a type argument. I promised I'd add an assert so here it is. One place needed adjusting, the comment explains why. Bootstrapped/regtested on x86_64-pc-l

[PATCH] c++: fix broken copy elision with nested TARGET_EXPRs [PR105550]

2022-05-26 Thread Marek Polacek via Gcc-patches
In this problem, we are failing to properly perform copy elision with a conditional operator, so this: constexpr A a = true ? A{} : A{}; fails with: error: 'A{((const A*)(&))}' is not a constant expression The whole initializer is TARGET_EXPR }> : TARGET_EXPR }>> where the outermost TAR

Re: [PATCH v2] c++: suppress -Waddress warnings with *_cast [PR105569]

2022-05-26 Thread Marek Polacek via Gcc-patches
On Thu, May 26, 2022 at 09:26:16AM -0400, Jason Merrill wrote: > On 5/25/22 16:25, Marek Polacek wrote: > > On Wed, May 18, 2022 at 09:43:47AM -0400, Jason Merrill wrote: > > > On 5/16/22 13:06, Marek Polacek wrote: > > > > dynamic_cast can legally return nullptr,

[PATCH v2] c++: suppress -Waddress warnings with *_cast [PR105569]

2022-05-25 Thread Marek Polacek via Gcc-patches
On Wed, May 18, 2022 at 09:43:47AM -0400, Jason Merrill wrote: > On 5/16/22 13:06, Marek Polacek wrote: > > dynamic_cast can legally return nullptr, so I don't think it's helpful > > for -Waddress to warn for > > > >if (dynamic_cast(&ref)) > >

Re: [PATCH] c++: fix ICE on invalid attributes [PR96637]

2022-05-25 Thread Marek Polacek via Gcc-patches
On Tue, May 24, 2022 at 08:22:22AM -0400, Jason Merrill wrote: > On 4/29/22 10:12, Marek Polacek wrote: > > This patch fixes crashes with invalid attributes. Arguably it could > > make sense to assert seen_error() too. > > So in this testcase we have TREE_CHAIN of a

Re: [wwwdocs] Add C status page

2022-05-24 Thread Marek Polacek via Gcc-patches
On Tue, May 24, 2022 at 06:11:09PM +, Joseph Myers wrote: > On Tue, 24 May 2022, Marek Polacek via Gcc-patches wrote: > > > I thought it'd be nice to have a table that documents our C support > > status, like we have https://gcc.gnu.org/projects/cxx-status.html for

Re: [PATCH v5] c++: ICE with temporary of class type in DMI [PR100252]

2022-05-24 Thread Marek Polacek via Gcc-patches
On Tue, May 24, 2022 at 04:01:37PM -0400, Jason Merrill wrote: > On 5/24/22 09:55, Marek Polacek wrote: > > On Tue, May 24, 2022 at 08:36:39AM -0400, Jason Merrill wrote: > > > On 5/16/22 11:36, Marek Polacek wrote: > > > > +static tree > > > > +replace_pl

<    2   3   4   5   6   7   8   9   10   11   >