Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preprocessor: fix duplicate pw3_padded_arg warnings #834

Merged
merged 3 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions libs/preprocessor/src/processor/defines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, sync::Arc};

use hemtt_workspace::{
position::Position,
reporting::{Output, Symbol, Token},
reporting::{Code, Output, Symbol, Token},
};
use peekmore::{PeekMore, PeekMoreIterator};

Expand Down Expand Up @@ -238,12 +238,18 @@ impl Processor {
{
for token in [value.first(), value.last()] {
if token.map_or(false, |t| t.symbol().is_whitespace()) {
self.warnings.push(Arc::new(PaddedArg::new(
let warning = PaddedArg::new(
Box::new(
(**token.expect("token exists from map_or check")).clone(),
),
ident_string.clone(),
)));
);

if !self.warnings.iter().any(|w| {
w.ident() == warning.ident() && w.token() == warning.token()
}) {
self.warnings.push(Arc::new(warning));
}
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions libs/preprocessor/tests/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ fn check(dir: &str) {
.unwrap();
let warning = config
.warnings()
.first()
.unwrap()
.diagnostic()
.unwrap()
.to_string(&WorkspaceFiles::new());
.iter()
.map(|w| w.diagnostic().unwrap().to_string(&WorkspaceFiles::new()))
.collect::<String>();
if expected.is_empty() {
std::fs::write(folder.join("stderr.ansi"), warning.replace('\r', "")).unwrap();
}
Expand All @@ -66,3 +64,4 @@ bootstrap!(pw1_redefine);
bootstrap!(pw1_redefine_stack);
bootstrap!(pw3_padded_arg);
bootstrap!(pw3_padded_arg_duplicates);
bootstrap!(pw3_padded_arg_inner);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define TEST1(var1, var2) INNER(var1, var2)
#define TEST2(var1, var2) INNER(var1, var2) // Separate macro to trigger unique warning for INNER padding
#define INNER(var1, var2) var1 var2

TEST1(John,Smith); // Only inner
TEST2(John, Smith); // Both call and inner
27 changes: 27 additions & 0 deletions libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
warning[PW3]: padding a macro argument
┌─ source.hpp:1:38
│
1 │ #define TEST1(var1, var2) INNER(var1, var2)
│ ^ padding a macro argument
│
= note: padding a macro argument is likely unintended
= note: occured in: `INNER`

warning[PW3]: padding a macro argument
┌─ source.hpp:6:12
│
6 │ TEST2(John, Smith); // Both call and inner
│ ^ padding a macro argument
│
= note: padding a macro argument is likely unintended
= note: occured in: `TEST2`

warning[PW3]: padding a macro argument
┌─ source.hpp:2:38
│
2 │ #define TEST2(var1, var2) INNER(var1, var2) // Separate macro to trigger unique warning for INNER padding
│ ^ padding a macro argument
│
= note: padding a macro argument is likely unintended
= note: occured in: `INNER`

Loading