diff --git a/Src/Compilers/CSharp/Source/Parser/DirectiveParser.cs b/Src/Compilers/CSharp/Source/Parser/DirectiveParser.cs
index 65175af3a988e17c1384082207666fefc7116bbd..da913817129ef95aa717dbc3b3d72750400ca348 100644
--- a/Src/Compilers/CSharp/Source/Parser/DirectiveParser.cs
+++ b/Src/Compilers/CSharp/Source/Parser/DirectiveParser.cs
@@ -398,7 +398,11 @@ private DirectiveTriviaSyntax ParsePragmaDirective(SyntaxToken hash, SyntaxToken
{
string value = (string)id.Value;
var messageProvider = MessageProvider.Instance;
- if (value.StartsWith(messageProvider.CodePrefix))
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ id = this.AddError(id, ErrorCode.WRN_BadWarningNumber, value);
+ }
+ else if (value.StartsWith(messageProvider.CodePrefix))
{
// For diagnostic IDs of the form "CS[0-9]*", verify the error code is that of a warning
int compilerWarningNumber;
diff --git a/Src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs b/Src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
index f3799700fbe56040d283899f92c89b76295bedaa..895ba1d9250e752af9e983ec389f229fd60f0e5e 100644
--- a/Src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
+++ b/Src/Compilers/CSharp/Test/Syntax/Diagnostics/DiagnosticTest.cs
@@ -1519,6 +1519,36 @@ public static void Main()
Diagnostic(ErrorCode.WRN_StringOrNumericLiteralExpected, ","));
}
+ [WorkItem(913567)]
+ [Fact]
+ public void PragmaWarningWithErrors_EmptyStrings()
+ {
+ var text = @"
+public class C
+{
+ public static void Main()
+ {
+#pragma warning disable """"
+#pragma warning restore """"
+#pragma warning disable "" ""
+#pragma warning restore """ + "\t" + @"""
+ }
+}";
+ CreateCompilationWithMscorlib(text).VerifyDiagnostics(
+// (6,25): warning CS1691: '' is not a valid warning number
+// #pragma warning disable ""
+Diagnostic(ErrorCode.WRN_BadWarningNumber, "\"\"").WithArguments("").WithLocation(6, 25),
+// (7,25): warning CS1691: '' is not a valid warning number
+// #pragma warning restore ""
+Diagnostic(ErrorCode.WRN_BadWarningNumber, "\"\"").WithArguments("").WithLocation(7, 25),
+// (8,25): warning CS1691: ' ' is not a valid warning number
+// #pragma warning disable " "
+Diagnostic(ErrorCode.WRN_BadWarningNumber, "\" \"").WithArguments(" ").WithLocation(8, 25),
+// (9,25): warning CS1691: '{tab}' is not a valid warning number
+// #pragma warning restore "{tab}"
+Diagnostic(ErrorCode.WRN_BadWarningNumber, "\"\t\"").WithArguments("\t").WithLocation(9, 25));
+ }
+
[WorkItem(546814, "DevDiv")]
[Fact]
public void PragmaWarningAlign_0()
diff --git a/Src/Compilers/Core/Source/CodeAnalysisResources.Designer.cs b/Src/Compilers/Core/Source/CodeAnalysisResources.Designer.cs
index dba178b05bde0e34d9dfc71406fe659701a90503..d5e52cf6adfe589ca45c5476d4594d9597be8952 100644
--- a/Src/Compilers/Core/Source/CodeAnalysisResources.Designer.cs
+++ b/Src/Compilers/Core/Source/CodeAnalysisResources.Designer.cs
@@ -249,6 +249,15 @@ internal class CodeAnalysisResources {
}
}
+ ///
+ /// Looks up a localized string similar to A DiagnosticDescriptor must have an Id that is neiter null nor an empty string nor a string that only contains white space..
+ ///
+ internal static string DiagnosticIdCantBeNullOrWhitespace {
+ get {
+ return ResourceManager.GetString("DiagnosticIdCantBeNullOrWhitespace", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Empty or invalid file name.
///
diff --git a/Src/Compilers/Core/Source/CodeAnalysisResources.resx b/Src/Compilers/Core/Source/CodeAnalysisResources.resx
index db5ada69387016e8f77fa26ea68a9943d7dc23bd..60662ff610b882c7fa96ef20995f722bb16eb44e 100644
--- a/Src/Compilers/Core/Source/CodeAnalysisResources.resx
+++ b/Src/Compilers/Core/Source/CodeAnalysisResources.resx
@@ -363,4 +363,7 @@
The changes must be ordered and not overlapping.
+
+ A DiagnosticDescriptor must have an Id that is neiter null nor an empty string nor a string that only contains white space.
+
\ No newline at end of file
diff --git a/Src/Compilers/Core/Source/Diagnostic/DiagnosticDescriptor.cs b/Src/Compilers/Core/Source/Diagnostic/DiagnosticDescriptor.cs
index 541f22223b1f0d70f4e5f1454da2cbb93e21a1a2..c4ac1cec984c3e39f39a43f62e4c24f733e8a5d8 100644
--- a/Src/Compilers/Core/Source/Diagnostic/DiagnosticDescriptor.cs
+++ b/Src/Compilers/Core/Source/Diagnostic/DiagnosticDescriptor.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System;
using System.Collections.Generic;
-using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis
{
@@ -59,6 +59,11 @@ public class DiagnosticDescriptor
/// Optional custom tags for the diagnostic. See for some well known tags.
public DiagnosticDescriptor(string id, string description, string messageFormat, string category, DiagnosticSeverity defaultSeverity, bool isEnabledByDefault, params string[] customTags)
{
+ if (string.IsNullOrWhiteSpace(id))
+ {
+ throw new ArgumentException(CodeAnalysisResources.DiagnosticIdCantBeNullOrWhitespace, "id");
+ }
+
this.Id = id;
this.Description = description;
this.Category = category;