From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 3562D3853831 for ; Mon, 17 May 2021 17:14:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3562D3853831 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-bBGi9RpYNU-Lx4vsSZ67aQ-1; Mon, 17 May 2021 13:14:13 -0400 X-MC-Unique: bBGi9RpYNU-Lx4vsSZ67aQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B64B66D582; Mon, 17 May 2021 17:14:12 +0000 (UTC) Received: from localhost (unknown [10.33.36.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 635D810027C4; Mon, 17 May 2021 17:14:12 +0000 (UTC) Date: Mon, 17 May 2021 18:14:11 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] libstdc++: Fix filesystem::path constraints for volatile [PR 100630] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="mL+tsJaRI+jNCLJ+" Content-Disposition: inline X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URI_HEX autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 17:14:17 -0000 --mL+tsJaRI+jNCLJ+ Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline On 17/05/21 15:25 +0100, Jonathan Wakely wrote: >On 17/05/21 15:02 +0100, Jonathan Wakely wrote: >>The constraint check for filesystem::path construction uses >>decltype(__is_path_src(declval())) which mean it considers >>conversion from an rvalue. When Source is a volatile-qualified type >>it cannot use is_path_src(const Unknown&) because a const lvalue >>reference can only bind to a non-volatile rvalue. >> >>Since the relevant path members all have a const Source& parameter, >>the constraint should be defined in terms of declval(), >>not declval(). This avoids the problem of volatile-qualified >>rvalues, because we no longer use an rvalue at all. >> >>libstdc++-v3/ChangeLog: >> >> PR libstdc++/100630 >> * include/bits/fs_path.h (__is_constructible_from): Test >> construction from a const lvalue, not an rvalue. >> * include/experimental/bits/fs_path.h (__is_constructible_from): >> Likewise. >> * testsuite/27_io/filesystem/path/construct/100630.cc: New test. >> * testsuite/experimental/filesystem/path/construct/100630.cc: >> New test. >> >>Tested x86_64-linux, pushed to gcc-10 (this isn't needed for gcc-11 or >>trunk, but I also plan to backport it to gcc-9). > >Oh actually this is needed for experimental::filesystem::path on trun >kand gcc-11 (as I found when I added to the new tests to trunk) so >I'll fix it there too. Here's the patch for trunk and gcc-11. --mL+tsJaRI+jNCLJ+ Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="patch.txt" commit 45aa7a447652e8541cc381d7ab128544f81ed857 Author: Jonathan Wakely Date: Mon May 17 11:54:06 2021 libstdc++: Fix filesystem::path constraints for volatile [PR 100630] The constraint check for filesystem::path construction uses decltype(__is_path_src(declval())) which mean it considers conversion from an rvalue. When Source is a volatile-qualified type it cannot use is_path_src(const Unknown&) because a const lvalue reference can only bind to a non-volatile rvalue. Since the relevant path members all have a const Source& parameter, the constraint should be defined in terms of declval(), not declval(). This avoids the problem of volatile-qualified rvalues, because we no longer use an rvalue at all. libstdc++-v3/ChangeLog: PR libstdc++/100630 * include/experimental/bits/fs_path.h (__is_constructible_from): Test construction from a const lvalue, not an rvalue. * testsuite/27_io/filesystem/path/construct/100630.cc: New test. * testsuite/experimental/filesystem/path/construct/100630.cc: New test. diff --git a/libstdc++-v3/include/experimental/bits/fs_path.h b/libstdc++-v3/include/experimental/bits/fs_path.h index 2df2bba3dcd..1ecf2f3a7bd 100644 --- a/libstdc++-v3/include/experimental/bits/fs_path.h +++ b/libstdc++-v3/include/experimental/bits/fs_path.h @@ -124,7 +124,7 @@ namespace __detail template struct __constructible_from<_Source, void> - : decltype(__is_path_src(std::declval<_Source>(), 0)) + : decltype(__is_path_src(std::declval(), 0)) { }; template + +void f(bool) { } +void f(const std::filesystem::path&) { } + +void +test_100630() +{ + volatile bool b = true; + f(b); +} diff --git a/libstdc++-v3/testsuite/experimental/filesystem/path/construct/100630.cc b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/100630.cc new file mode 100644 index 00000000000..b2428ff74cf --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/filesystem/path/construct/100630.cc @@ -0,0 +1,14 @@ +// { dg-do compile { target c++11 } } +// { dg-require-filesystem-ts "" } + +#include + +void f(bool) { } +void f(const std::experimental::filesystem::path&) { } + +void +test_100630() +{ + volatile bool b = true; + f(b); +} --mL+tsJaRI+jNCLJ+--