Skip to content

Commit

Permalink
preprocessor: fix duplicate pw3_padded_arg warnings (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eathox authored Nov 10, 2024
1 parent 83ef17c commit 40563a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
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`

0 comments on commit 40563a3

Please sign in to comment.