From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 112906 invoked by alias); 3 Mar 2020 10:57:11 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 112894 invoked by uid 89); 3 Mar 2020 10:57:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=H*RU:209.85.128.52, HX-Received:a7b, HX-Spam-Relays-External:209.85.128.52 X-HELO: mail-wm1-f52.google.com Received: from mail-wm1-f52.google.com (HELO mail-wm1-f52.google.com) (209.85.128.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Mar 2020 10:57:09 +0000 Received: by mail-wm1-f52.google.com with SMTP id p9so2592707wmc.2 for ; Tue, 03 Mar 2020 02:57:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=9ehj1faaQ0cnfYyDklib0KU7THBh0Gqj7RQ9PwFcWA4=; b=WGTZa+k/6sfl2zmL+hlZnjDZX+wNnGSGPivGqm8BJ7Dl/nCyRCN3Yb+zk3ECou5wVq jmF9fNi+0vCIawzNI4aOIc5xwPMpssXswxuvbkLcHFMOwWitRCzedmMozWg45fsqIqEc O1TsKlqkkYyO/AQvNhR8ZillBa5slHvyn53CO/vTcE6Y5lfCq0hodL4VQi9iQJFHV1Ee H0bAVRaAkvjTIdON/8U7ZkAgvHmOMv4yMLf1sqHziFi5yPe16I+ErHidB/01vlp/sXqE vMxgV3lBRzQdfJpEvUgiYRasB2JzngIjeWzZhdeJqjvVu9tmcMhMI/4gAAm9ZdJIghzZ BVyg== MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Tue, 03 Mar 2020 10:57:00 -0000 Message-ID: Subject: Re: C++ expected-to-fail compilation goes through by not detecting mutable-specifier on lambda... To: leon zadorin Cc: gcc-help Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2020-03/txt/msg00011.txt On Mon, 2 Mar 2020 at 03:55, leon zadorin wrote: > > On Mon, Mar 2, 2020 at 1:57 PM leon zadorin wrote: > > > > template > > void foo(T const f) > > { > > f(); > > } > ... > > the effect of 'mutable' (i.e. making operator()() non-const) are not > detected by GCC/clang to a point where both of the following compile ok: > > int main() > > { > > foo([](){}); > > foo([]() mutable {}); > > } > > > > ... actually never mind, I take it back :) I think GCC/clang are ok in > that regard, reading https://en.cppreference.com/w/cpp/language/lambda > "mutable: allows body to modify the parameters captured by copy, and to > call their non-const member functions" > > makes it more clear for me... as in the above lambdas have no captures > anyways (i.e. no effect), and with any captures (e.g. mutating with > mutable) the expected compilation failure becomes evident, so in effect > GCC/clang are doing this fine :) What they're doing seems kinda OK, but I think it's not actually allowed by the standard. The wording does say that unless the lambda uses the mutable keyword, the function call operator is const-qualified. So I think this is a bug.