diff --git a/libs/preprocessor/src/processor/defines.rs b/libs/preprocessor/src/processor/defines.rs index 6dfdd0d0..528c5e4b 100644 --- a/libs/preprocessor/src/processor/defines.rs +++ b/libs/preprocessor/src/processor/defines.rs @@ -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}; @@ -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)); + } } } } diff --git a/libs/preprocessor/tests/warnings.rs b/libs/preprocessor/tests/warnings.rs index 300eadee..872ffdfa 100644 --- a/libs/preprocessor/tests/warnings.rs +++ b/libs/preprocessor/tests/warnings.rs @@ -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::(); if expected.is_empty() { std::fs::write(folder.join("stderr.ansi"), warning.replace('\r', "")).unwrap(); } @@ -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); diff --git a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp new file mode 100644 index 00000000..f6f9eae8 --- /dev/null +++ b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/source.hpp @@ -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 diff --git a/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi new file mode 100644 index 00000000..feb57506 --- /dev/null +++ b/libs/preprocessor/tests/warnings/pw3_padded_arg_inner/stderr.ansi @@ -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` +