Index: include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- include/clang/Basic/DiagnosticLexKinds.td	(revision 172546)
+++ include/clang/Basic/DiagnosticLexKinds.td	(working copy)
@@ -285,6 +285,8 @@
 def note_macro_here : Note<"macro %0 defined here">;
 
 def err_pp_invalid_directive : Error<"invalid preprocessing directive">;
+def err_pp_directive_required : Error<
+  "%0 must be used within a preprocessing directive">;
 def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
 def err_pp_file_not_found_not_fatal : Error<
   "'%0' file not found with <angled> include; use \"quotes\" instead">;
Index: include/clang/Lex/PreprocessorLexer.h
===================================================================
--- include/clang/Lex/PreprocessorLexer.h	(revision 172546)
+++ include/clang/Lex/PreprocessorLexer.h	(working copy)
@@ -144,6 +144,12 @@
     ParsingPreprocessorDirective = f;
   }
 
+  /// \brief Return true if this lexer is currently lexing a preprocessor 
+  /// directive.
+  bool isParsingPreprocessorDirective() const { 
+    return ParsingPreprocessorDirective;
+  }
+
   /// \brief Return true if this lexer is in raw mode or not.
   bool isLexingRawMode() const { return LexingRawMode; }
 
Index: lib/Lex/PPMacroExpansion.cpp
===================================================================
--- lib/Lex/PPMacroExpansion.cpp	(revision 172555)
+++ lib/Lex/PPMacroExpansion.cpp	(working copy)
@@ -968,6 +968,14 @@
   // that location.  If not, use the end of this location instead.
   SourceLocation LParenLoc = Tok.getLocation();
 
+  // We only want to get the file name if we're currently within a 
+  // preprocessor directive.
+  if (PP.getCurrentLexer() && 
+      !PP.getCurrentLexer()->isParsingPreprocessorDirective()) {
+    PP.Diag(LParenLoc, diag::err_pp_directive_required) << II->getName();
+    return false;
+  }
+
   // Get '('.
   PP.LexNonComment(Tok);
 
Index: test/Preprocessor/has_include.c
===================================================================
--- test/Preprocessor/has_include.c	(revision 172546)
+++ test/Preprocessor/has_include.c	(working copy)
@@ -91,6 +91,12 @@
   #error "__has_include with macro failed (2)."
 #endif
 
+// Try as non-preprocessor directives
+void foo( void ) {
+  __has_include_next("stdint.h")  // expected-warning {{#include_next in primary source file}} expected-error {{__has_include_next must be used within a preprocessing directive}}
+  __has_include("stdint.h")  // expected-error {{__has_include must be used within a preprocessing directive}}
+}
+
 // Try badly formed expressions.
 // FIXME: We can recover better in almost all of these cases. (PR13335)
 
@@ -126,7 +132,7 @@
 #if __has_include(stdint.h>)
 #endif
 
-// expected-error@+1 {{missing '(' after '__has_include'}}
+// expected-error@+1 {{__has_include must be used within a preprocessing directive}}
 __has_include
 
 // expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}}  // expected-note@+1 {{to match this '('}}
