@@ -222,4 +222,43 @@ struct hash<int> { // COMPLIANT - rule does not apply to template
222222 std::size_t operator ()(const int &x) const {
223223 return static_cast <std::size_t >(x);
224224 }
225- };
225+ };
226+
227+ // Test case for RULE-5-10-1 false positive fix: a local variable or function
228+ // parameter is scoped to the body of its enclosing function, not to the
229+ // namespace that function happens to be declared in. This matters for the
230+ // body of an explicit template specialization that C++ explicitly permits
231+ // users to add to namespace `std` (such as `std::hash<UserType>`): the
232+ // parameter and local names below are ordinary user-chosen identifiers and
233+ // do not themselves become new members of namespace `std`.
234+ struct UserTypeForHash {
235+ int payload;
236+ };
237+
238+ namespace std {
239+ template <typename T>
240+ struct hash ; // forward declaration of the primary
241+ // template that is specialized below
242+
243+ template <> struct hash <UserTypeForHash> {
244+ std::size_t
245+ operator ()(const UserTypeForHash &value) const noexcept { // COMPLIANT -
246+ // 'value' is a
247+ // parameter
248+ // scoped to the
249+ // function body,
250+ // not a member
251+ // of namespace
252+ // std
253+ std::size_t result = static_cast <std::size_t >(
254+ value.payload ); // COMPLIANT - 'result' is a local variable scoped to
255+ // the function body, not a member of namespace std
256+ return result;
257+ }
258+ };
259+
260+ // A genuinely new function declared directly in namespace std remains a
261+ // violation: this is not a permitted specialization, and it does introduce a
262+ // new name into the reserved namespace.
263+ void new_std_function () {} // NON_COMPLIANT - namespace std is reserved
264+ } // namespace std
0 commit comments