From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 00B453858020; Fri, 11 Feb 2022 12:31:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00B453858020 From: "asynts+bugs at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: =?UTF-8?B?W0J1ZyBjKysvMTAxMTQwXSBbbW9kdWxlc10gbm8gbWF0Y2hpbmcg?= =?UTF-8?B?ZnVuY3Rpb24gZm9yIGNhbGwgdG8g4oCYb3BlcmF0b3IgbmV3KHNpemV0eXBl?= =?UTF-8?B?LCB2b2lkKinigJk=?= Date: Fri, 11 Feb 2022 12:31:54 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: asynts+bugs at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Feb 2022 12:31:55 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101140 Paul Scharnofske changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |asynts+bugs at gmail dot c= om --- Comment #2 from Paul Scharnofske --- I had a very similar problem: ```c++ // foo.cpp export module foo; using size_t =3D decltype(sizeof(int)); void* operator new(size_t, void *pointer) { return pointer; } export template void foo() { T t; new (&t) T; } ``` ```c++ // bar.cpp export module bar; import foo; void bar() { foo(); } ``` ```c++ // main.cpp export module main; import foo; import bar; int main() { } ``` ```none $ ~/.local/lib/gcc-trunk/bin/g++ --version g++ (GCC) 12.0.1 20220211 (experimental) Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ ~/.local/lib/gcc-trunk/bin/g++ -Wall -Wextra -std=3Dc++20 -fmodules-ts fo= o.cpp bar.cpp main.cpp In module foo, imported at bar.cpp:4: foo.cpp: In instantiation of 'void foo@foo() [with T =3D int]': bar.cpp:7:13: required from here foo.cpp:14:5: error: no matching function for call to 'operator new(sizetyp= e, int*)' 14 | new (&t) T; | ^~~~~~~~~~ : note: candidate: 'void* operator new(long unsigned int)' : note: candidate expects 1 argument, 2 provided : note: candidate: 'void* operator new(long unsigned int, std::align_val_t)' : note: no known conversion for argument 2 from 'int*' to 'std::align_val_t' bar.cpp:2:8: warning: not writing module 'bar' due to errors 2 | export module bar; | ^~~~~~ In module imported at main.cpp:5:1: bar: error: failed to read compiled module: No such file or directory bar: note: compiled module file is 'gcm.cache/bar.gcm' bar: note: imports must be built before being imported bar: fatal error: returning to the gate for a mechanical issue compilation terminated. ``` https://godbolt.org/z/es5he4hc4 It appears that the compiler tries to lookup the placement new operator in = the module where the template instantiation happens. In my mind, the correct behavior would be to look this up in the module whe= re the template is defined. However, I am not familiar with the standard. There are several ways, this code can be changed to work: 1. Add 'export' to the 'operator new'. However, this requires that the module that defines the operator new is imported by the module directly. https://godbolt.org/z/nxY681PeK 2. Remove the template parameter from 'foo'. https://godbolt.org/z/1T9Erjdz3=