Give better error diagnostic in cpdf_dictionary.h

Use a static_assert to give a better compiler error when using
CPDF_Dictionary::SetNewFor() incorrectly, as suggested on
https://pdfium-review.googlesource.com/116370 for the same situation
with CPDF_Array.

Bug: pdfium:2119
Change-Id: Ic39474c3ed54b0a3624ac77d4bf3e70cc54bea4a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116450
Reviewed-by: Thomas Sepez <tsepez@google.com>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index a18f2f3..0d0b8cc 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -87,12 +87,12 @@
   // Prefer using these templates over calls to SetFor(), since by creating
   // a new object with no previous references, they ensure cycles can not be
   // introduced.
-  // A stream must be indirect and added as a `CPDF_Reference` instead.
   template <typename T, typename... Args>
-  typename std::enable_if<!CanInternStrings<T>::value &&
-                              !std::is_same<T, CPDF_Stream>::value,
-                          RetainPtr<T>>::type
+  typename std::enable_if<!CanInternStrings<T>::value, RetainPtr<T>>::type
   SetNewFor(const ByteString& key, Args&&... args) {
+    static_assert(!std::is_same<T, CPDF_Stream>::value,
+                  "Cannot set a CPDF_Stream directly. Add it indirectly as a "
+                  "`CPDF_Reference` instead.");
     return pdfium::WrapRetain(static_cast<T*>(SetForInternal(
         key, pdfium::MakeRetain<T>(std::forward<Args>(args)...))));
   }