Don't use fprintf to emit this diagnostic!

llvm-svn: 246526
This commit is contained in:
Richard Smith 2015-09-01 02:35:58 +00:00
parent 51d2d0f668
commit b5aaf5a57a
3 changed files with 10 additions and 3 deletions

View File

@ -111,6 +111,10 @@ def note_module_odr_violation_different_definitions : Note<
def err_module_odr_violation_different_instantiations : Error<
"instantiation of %q0 is different in different modules">;
def warn_module_uses_date_time : Warning<
"%select{precompiled header|module}0 uses __DATE__ or __TIME__">,
InGroup<DiagGroup<"pch-date-time">>;
} // let CategoryName
} // let Component

View File

@ -43,6 +43,7 @@
#include "clang/Sema/IdentifierResolver.h"
#include "clang/Sema/Sema.h"
#include "clang/Serialization/ASTReader.h"
#include "clang/Serialization/SerializationDiagnostic.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/Hashing.h"
@ -2054,10 +2055,9 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP, bool IsModule) {
Stream.EnterSubblock(PREPROCESSOR_BLOCK_ID, 3);
// If the AST file contains __DATE__ or __TIME__ emit a warning about this.
// FIXME: use diagnostics subsystem for localization etc.
// FIXME: Include a location for the use, and say which one was used.
if (PP.SawDateOrTime())
fprintf(stderr, "warning: precompiled header used __DATE__ or __TIME__.\n");
PP.Diag(SourceLocation(), diag::warn_module_uses_date_time) << IsModule;
// Loop over all the macro directives that are live at the end of the file,
// emitting each to the PP section.

View File

@ -0,0 +1,3 @@
// RUN: %clang_cc1 -x c-header %s -emit-pch -o %t 2>&1 | FileCheck %s
// CHECK: precompiled header uses __DATE__ or __TIME__
const char *p = __DATE__;