-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In MSVC compatibility mode, friend function declarations behave as fu…
…nction declarations Before C++20, MSVC treated any friend function declaration as a function declaration, so the following code would compile despite funGlob being declared after its first call: ``` class Glob { public: friend void funGlob(); void test() { funGlob(); } }; void funGlob() {} ``` This proposed patch mimics the MSVC behavior when in MSVC compatibility mode Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D124613
- Loading branch information
1 parent
bc8e601
commit ad47114
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: %clang_cc1 -std=c++03 -fms-compatibility -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -std=c++17 -fms-compatibility -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fsyntax-only -verify=modern %s | ||
#if __cplusplus < 202002L | ||
// expected-no-diagnostics | ||
#endif | ||
|
||
namespace ns { | ||
|
||
class C { | ||
public: | ||
template <typename T> | ||
friend void funtemp(); | ||
|
||
friend void fun(); | ||
|
||
void test() { | ||
::ns::fun(); // modern-error {{no member named 'fun' in namespace 'ns'}} | ||
|
||
// modern-error@+3 {{no member named 'funtemp' in namespace 'ns'}} | ||
// modern-error@+2 {{expected '(' for function-style cast or type construction}} | ||
// modern-error@+1 {{expected expression}} | ||
::ns::funtemp<int>(); | ||
} | ||
}; | ||
|
||
void fun() { | ||
} | ||
|
||
template <typename T> | ||
void funtemp() {} | ||
|
||
} // namespace ns | ||
|
||
class Glob { | ||
public: | ||
friend void funGlob(); | ||
|
||
void test() { | ||
funGlob(); // modern-error {{use of undeclared identifier 'funGlob'}} | ||
} | ||
}; | ||
|
||
void funGlob() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters