Clang error: overriding virtual function must specify the same code segment as its overridden function (err_mismatched_code_seg_override)
Jump to navigation
Jump to search
Text | error: overriding virtual function must specify the same code segment as its overridden function (since 7.0) |
---|---|
Type | Error |
Category | Semantic Issue (since 7.0) |
Internal Id | err_mismatched_code_seg_override (since 7.0) |
Internal Message | overriding virtual function must specify the same code segment as its overridden function (since 7.0)
|
Regular Expression | (?:error|fatal error)\: overriding virtual function must specify the same code segment as its overridden function
|
First Commit | 2018-05-16 64144eb194c8 Add support for __declspec(code_seg("segname")) |
Description
Example
Flags | -xc++ -fdeclspec
|
|
---|---|---|
Source |
__declspec(code_seg(".text")) struct A {
virtual void f() {}
};
struct B : A {
__declspec(code_seg(".text_different")) void f() override {}
// Different code segment
};
int main() {
return 0;
}
| |
Compiler Output |
<source>:1:12: warning: attribute 'code_seg' is ignored, place it after "struct" to apply attribute to type declaration [-Wignored-attributes] <source>:6:50: error: overriding virtual function must specify the same code segment as its overridden function <source>:2:18: note: previous declaration is here |
Clang Internals (17.0.6)
Git Commit Message
Add support for __declspec(code_seg("segname")) Add support for __declspec(code_seg("segname")) This patch is built on the existing support for #pragma code_seg. The code_seg declspec is allowed on functions and classes. The attribute enables the placement of code into separate named segments, including compiler-generated members and template instantiations. For more information, please see the following: https://msdn.microsoft.com/en-us/library/dn636922.aspx A new CodeSeg attribute is used instead of adding a new spelling to the existing Section attribute since they don’t apply to the same Subjects. Section attributes are also added for the code_seg declspec since they are used for #pragma code_seg. No CodeSeg attributes are added to the AST. The patch is written to match with the Microsoft compiler’s behavior even where that behavior is a little complicated (see https://reviews.llvm.org/D22931, the Microsoft feedback page is no longer available since MS has removed the page). That code is in getImplicitSectionAttrFromClass routine. Diagnostics messages are added to match with the Microsoft compiler for code-seg attribute mismatches on base and derived classes and virtual overrides. Differential Revision: https://reviews.llvm.org/D43352 llvm-svn: 332470
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDeclCXX.cpp (line 17993)
bool Sema::CheckOverridingFunctionAttributes(const CXXMethodDecl *New, const CXXMethodDecl *Old) {
// ...
if ((NewCSA || OldCSA) && (!OldCSA || !NewCSA || NewCSA->getName() != OldCSA->getName())) {
Diag(New->getLocation(), diag::err_mismatched_code_seg_override);
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaCXX/code-seg.cpp
- clang/test/SemaCXX/code-seg.cpp:60:7: error: overriding virtual function must specify the same code segment as its overridden function
- clang/test/SemaCXX/code-seg.cpp:70:15: error: overriding virtual function must specify the same code segment as its overridden function
- clang/test/SemaCXX/code-seg.cpp:73:46: error: overriding virtual function must specify the same code segment as its overridden function