public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105752] New: Template function can access private member
@ 2022-05-27 16:36 csaba_22 at yahoo dot co.uk
2022-05-27 16:40 ` [Bug c++/105752] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: csaba_22 at yahoo dot co.uk @ 2022-05-27 16:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
Bug ID: 105752
Summary: Template function can access private member
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: csaba_22 at yahoo dot co.uk
Target Milestone: ---
The following code
class Outer
{
private: // !!!!!
struct Inner
{};
};
template<typename T>
struct Meow
{
void purr() {
Outer::Inner oi;
}
};
int main()
{
Meow<double> kitty;
//kitty.purr();
}
is compiled by GCC from 4.1.2 to 12.1.0, but is rejected by all clang releases
available on godbolt.
https://godbolt.org/z/58Yca6dah
Also mentioned here:
https://stackoverflow.com/questions/28596242/accessing-private-inner-class-type-from-non-member-template-function
If the call to the function is uncommented, then GCC also emits an error.
Visual Studio 2013 update 4 also emits an error (allegedly), so this sounds
like a bug.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105752] Template function can access private member
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
@ 2022-05-27 16:40 ` pinskia at gcc dot gnu.org
2022-05-27 17:12 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-27 16:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There might already been a dup of this. Gcc does not do access checking until
instantiation time (as you saw) even for non dependent things.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105752] Template function can access private member
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
2022-05-27 16:40 ` [Bug c++/105752] " pinskia at gcc dot gnu.org
@ 2022-05-27 17:12 ` redi at gcc dot gnu.org
2022-05-27 17:13 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-27 17:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Which is permitted by the standard.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105752] Template function can access private member
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
2022-05-27 16:40 ` [Bug c++/105752] " pinskia at gcc dot gnu.org
2022-05-27 17:12 ` redi at gcc dot gnu.org
@ 2022-05-27 17:13 ` redi at gcc dot gnu.org
2022-05-30 17:49 ` csaba_22 at yahoo dot co.uk
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2022-05-27 17:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And if you never instantiate the function, who cares? It doesn't actually
access the private member, because you never call it. And if you try to, it
doesn't compile.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105752] Template function can access private member
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
` (2 preceding siblings ...)
2022-05-27 17:13 ` redi at gcc dot gnu.org
@ 2022-05-30 17:49 ` csaba_22 at yahoo dot co.uk
2022-06-02 9:10 ` csaba_22 at yahoo dot co.uk
2022-06-02 13:29 ` ppalka at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: csaba_22 at yahoo dot co.uk @ 2022-05-30 17:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
--- Comment #4 from Csaba Ráduly <csaba_22 at yahoo dot co.uk> ---
Looks like there *was* a bug, I just wasn't able to properly reproduce it
initially:
#include <type_traits>
#include <utility>
class CB {
struct DCB {};
};
struct NMC1 : public CB {
int meow() const { return __LINE__; }
};
struct CC {
template <typename ... Args>
int meow(Args&&... args) {
if constexpr(std::is_same_v<
decltype(std::declval<NMC1>().meow(std::forward<Args>(args)...)), CB::DCB>) {
return __LINE__;
}
else {
return __LINE__;
}
}
};
int main()
{
CC cc;
return cc.meow();
}
(accepted by GCC 10, rejected by clang and GCC11).
https://godbolt.org/z/81rWdf6v8
This has been fixed between GCC 10.3 and 11.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105752] Template function can access private member
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
` (3 preceding siblings ...)
2022-05-30 17:49 ` csaba_22 at yahoo dot co.uk
@ 2022-06-02 9:10 ` csaba_22 at yahoo dot co.uk
2022-06-02 13:29 ` ppalka at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: csaba_22 at yahoo dot co.uk @ 2022-06-02 9:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
--- Comment #5 from Csaba Ráduly <csaba_22 at yahoo dot co.uk> ---
The fact that GCC 11 shows an error for the code in comment #4 suggests that
this was a bug which was fixed. Does it ring a bell to anyone? This bug should
probably marked as a duplicate, but of which other bug?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/105752] Template function can access private member
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
` (4 preceding siblings ...)
2022-06-02 9:10 ` csaba_22 at yahoo dot co.uk
@ 2022-06-02 13:29 ` ppalka at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-06-02 13:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105752
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
CC| |ppalka at gcc dot gnu.org
--- Comment #6 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Csaba Ráduly from comment #5)
> The fact that GCC 11 shows an error for the code in comment #4 suggests that
> this was a bug which was fixed. Does it ring a bell to anyone? This bug
> should probably marked as a duplicate, but of which other bug?
Looks like we started to correctly reject the comment #4 testcase after
r11-6800-g29853c653245c3. Since the testcase is pretty similar to the one from
PR58993, I guess we can mark this a dup of that PR.
*** This bug has been marked as a duplicate of bug 58993 ***
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-06-02 13:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27 16:36 [Bug c++/105752] New: Template function can access private member csaba_22 at yahoo dot co.uk
2022-05-27 16:40 ` [Bug c++/105752] " pinskia at gcc dot gnu.org
2022-05-27 17:12 ` redi at gcc dot gnu.org
2022-05-27 17:13 ` redi at gcc dot gnu.org
2022-05-30 17:49 ` csaba_22 at yahoo dot co.uk
2022-06-02 9:10 ` csaba_22 at yahoo dot co.uk
2022-06-02 13:29 ` 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).