Clang warning: ... does not match previous declaration [-Wsection] (warn_mismatched_section)
Jump to navigation
Jump to search
Text |
(since 7.0) | |||||
---|---|---|---|---|---|---|
Type | Warning | |||||
Category | Semantic Issue | |||||
Internal Id | warn_mismatched_section | |||||
Active by Default | Yes | |||||
Flags | -Wno-section (3 elements) | |||||
Internal Message | %select{codeseg|section}0 does not match previous declaration (since 7.0)section does not match previous declaration (until 6.0)
| |||||
Regular Expression | (?:warning|error|fatal error)\: (?:codeseg|section) does not match previous declaration \[(?:\-Werror,)?\-Wsection[^\]]*\]
| |||||
First Commit | 2012-05-13 9869c3a10fdb Produce a warning for mismatched section attributes. Completest pr9356. |
Description
Example
Flags | -xc
|
|
---|---|---|
Source |
__attribute__((section(".text"))) void f(void) {}
__attribute__((section(".data"))) void f(void);
| |
Compiler Output |
<source>:2:16: warning: section does not match previous declaration [-Wsection] <source>:1:16: note: previous attribute is here |
Clang Internals (17.0.6)
Git Commit Message
Produce a warning for mismatched section attributes. Completest pr9356. llvm-svn: 156727
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/SemaDecl.cpp (line 3281)
/// mergeDeclAttributes - Copy attributes from the Old decl to the New one.
void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old, AvailabilityMergeKind AMK) {
// ...
if (NewCSA && !Old->hasAttr<CodeSegAttr>() && !NewCSA->isImplicit() && isa<CXXMethodDecl>(New)) {
Diag(New->getLocation(), diag::warn_mismatched_section) << 0 /*codeseg*/;
clang/lib/Sema/SemaDeclAttr.cpp (line 3296)
SectionAttr *Sema::mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Name) {
// ...
if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) {
// ...
Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) << 1 /*section*/;
clang/lib/Sema/SemaDeclAttr.cpp (line 3380)
CodeSegAttr *Sema::mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, StringRef Name) {
// ...
if (const auto *ExistingAttr = D->getAttr<CodeSegAttr>()) {
// ...
Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section) << 0 /*codeseg*/;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaCXX/attr-section.cpp
- clang/test/SemaCXX/attr-section.cpp:15:21: warning: section does not match previous declaration [-Wsection]
- clang/test/SemaCXX/attr-section.cpp:42:18: warning: section does not match previous declaration [-Wsection]