public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100881] New: [c++ modules][possible bug?] default arguments break when the default argument's type isn't explicitly included/exported
@ 2021-06-02 18:49 evanc.github at gmail dot com
  2022-12-19 20:39 ` [Bug c++/100881] [modules] " cvs-commit at gcc dot gnu.org
  2022-12-19 20:41 ` ppalka at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: evanc.github at gmail dot com @ 2021-06-02 18:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100881

            Bug ID: 100881
           Summary: [c++ modules][possible bug?] default arguments break
                    when the default argument's type isn't explicitly
                    included/exported
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: evanc.github at gmail dot com
  Target Milestone: ---

Created attachment 50911
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50911&action=edit
Preprocessed output of foo.cc

GCC Version / steps to reproduce:

$ g++ -v    
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-11.1.1-20210428/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.1 20210428 (Red Hat 11.1.1-1) (GCC) 


$ cat foo.cc 
module;
#include <source_location>
export module foo;

export void log(const std::source_location& loc =
std::source_location::current()) {
    // 
}

$ cat main.cc
import foo;

int main() {
    log();
}

$ g++ -fmodules-ts -std=c++20 -c foo.cc -o foo.o
$ g++ -fmodules-ts -std=c++20 main.cc foo.o
main.cc: In function ‘int main()’:
main.cc:4:8: error: ‘source_location’ is not a member of ‘std’
    4 |     log();
      |     ~~~^~
main.cc:1:1: note: ‘std::source_location’ is defined in header
‘<source_location>’; did you forget to ‘#include <source_location>’?
  +++ |+#include <source_location>
    1 | import foo;
main.cc:4:8: note: evaluating ‘__builtin_source_location’
    4 |     log();
      |     ~~~^~
In file included from foo.cc:2,
of module foo, imported at main.cc:1:
main.cc:4:8:   in ‘constexpr’ expansion of
‘std::source_location@foo::current(0)’
/usr/include/c++/11/source_location:54:23: error: cast from ‘const void*’ is
not allowed
   54 |       __ret._M_impl = static_cast <const __impl*>(__p);
      | 


=====================================================================================
Apologies if this isn't actually a bug, but it seemed to be. 

This error disappears when <source_location> is included in main.cc or `export
import <source_location` is present in foo.cc (along with a compiled header
unit for <source_location>).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/100881] [modules] default arguments break when the default argument's type isn't explicitly included/exported
  2021-06-02 18:49 [Bug c++/100881] New: [c++ modules][possible bug?] default arguments break when the default argument's type isn't explicitly included/exported evanc.github at gmail dot com
@ 2022-12-19 20:39 ` cvs-commit at gcc dot gnu.org
  2022-12-19 20:41 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-19 20:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100881

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:64f7a3b38765bcf7cdf5b37a991c06337468ad8b

commit r13-4800-g64f7a3b38765bcf7cdf5b37a991c06337468ad8b
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Dec 19 15:35:51 2022 -0500

    c++: modules and std::source_location::current() def arg [PR100881]

    We currently declare __builtin_source_location with a const void* return
    type instead of the actual type const std::source_location::__impl*, and
    later when folding this builtin we obtain the actual type via name lookup.

    But the below testcase demonstrates this approach seems to interact
    poorly with modules, since we may import an entity that uses
    std::source_location::current() in its default argument (or DMI) without
    necessarily importing <source_location>, and thus the name lookup for
    std::source_location will fail at the call site (when using the default
    argument) unless we also import <source_location>.

    This patch fixes this by instead initially declaring the builtin with an
    auto return type and updating it appropriately upon its first use (in
    standard code the first/only use would be in the definition of
    std::source_location).  Thus when folding calls to this builtin we can
    get at its return type through the type of the CALL_EXPR and avoid
    needing to do a name lookup.

            PR c++/100881

    gcc/cp/ChangeLog:

            * constexpr.cc (cxx_eval_builtin_function_call): Adjust calls
            to fold_builtin_source_location.
            * cp-gimplify.cc (cp_gimplify_expr): Likewise.
            (cp_fold): Likewise.
            (get_source_location_impl_type): Remove location_t parameter and
            adjust accordingly.  No longer static.
            (fold_builtin_source_location): Take a CALL_EXPR tree instead of a
            location and obtain the impl type from its return type.
            * cp-tree.h (enum cp_tree_index): Remove CPTI_SOURCE_LOCATION_IMPL
            enumerator.
            (source_location_impl): Remove.
            (fold_builtin_source_location): Adjust parameter type.
            (get_source_location_impl_type): Declare.
            * decl.cc (cxx_init_decl_processing): Declare
            __builtin_source_location with auto return type instead of
            const void*.
            (require_deduced_type): Update the return type of
            __builtin_source_location.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/srcloc3.C: Adjust expected note s/evaluating/using.
            * g++.dg/cpp2a/srcloc4.C: Likewise.
            * g++.dg/cpp2a/srcloc5.C: Likewise.
            * g++.dg/cpp2a/srcloc6.C: Likewise.
            * g++.dg/cpp2a/srcloc7.C: Likewise.
            * g++.dg/cpp2a/srcloc8.C: Likewise.
            * g++.dg/cpp2a/srcloc9.C: Likewise.
            * g++.dg/cpp2a/srcloc10.C: Likewise.
            * g++.dg/cpp2a/srcloc11.C: Likewise.
            * g++.dg/cpp2a/srcloc12.C: Likewise.
            * g++.dg/cpp2a/srcloc13.C: Likewise.
            * g++.dg/modules/pr100881_a.C: New test.
            * g++.dg/modules/pr100881_b.C: New test.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/100881] [modules] default arguments break when the default argument's type isn't explicitly included/exported
  2021-06-02 18:49 [Bug c++/100881] New: [c++ modules][possible bug?] default arguments break when the default argument's type isn't explicitly included/exported evanc.github at gmail dot com
  2022-12-19 20:39 ` [Bug c++/100881] [modules] " cvs-commit at gcc dot gnu.org
@ 2022-12-19 20:41 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-12-19 20:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100881

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 13, thanks for the bug report.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-19 20:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 18:49 [Bug c++/100881] New: [c++ modules][possible bug?] default arguments break when the default argument's type isn't explicitly included/exported evanc.github at gmail dot com
2022-12-19 20:39 ` [Bug c++/100881] [modules] " cvs-commit at gcc dot gnu.org
2022-12-19 20:41 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).