Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
>
Examples of errors detected by the V301…

Examples of errors detected by the V3012 diagnostic

V3012. The '?:' operator, regardless of its conditional expression, always returns one and the same value.


MonoDevelop

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: WindowCommands.NextDocument. MonoDevelop.Ide WindowCommands.cs 254


public enum WindowCommands
{
  NextDocument,
  PrevDocument,
  OpenDocumentList,
  OpenWindowList,
  SplitWindowVertically,
  SplitWindowHorizontally,
  UnsplitWindow,
  SwitchSplitWindow,
  SwitchNextDocument,
  SwitchPreviousDocument
}

protected static void Switch (bool next)
{
  if (!IdeApp.Preferences.EnableDocumentSwitchDialog) {
       IdeApp.CommandService.DispatchCommand (
         next ? WindowCommands.NextDocument :
                WindowCommands.NextDocument);
       return;
  }

  var toplevel = Window.ListToplevels ()
                       .FirstOrDefault (w => w.HasToplevelFocus)
                       ?? IdeApp.Workbench.RootWindow;
  var sw = new DocumentSwitcher (toplevel, next);
  sw.Present ();
}

MonoDevelop

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: result.Test.FullName. GuiUnit_NET_4_5 NUnit2XmlOutputWriter.cs 207


private void StartTestElement(ITestResult result)
{
  ITest test = result.Test;
  TestSuite suite = test as TestSuite;

  if (suite != null)
  {
    xmlWriter.WriteStartElement("test-suite");
    xmlWriter.WriteAttributeString("type", suite.TestType);
    xmlWriter.WriteAttributeString("name",
      suite.TestType == "Assembly" ?
        result.Test.FullName : result.Test.FullName);
  }
  ....
}

IronPython and IronRuby

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: newHandlers. DebugInfoRewriter.cs 252


protected override MSAst.Expression VisitTry(
  MSAst.TryExpression node) {
  ....
  if (newHandlers != null || newFinally != null) {
    node = Ast.MakeTry(node.Type, node.Body,
      newFinally != null ? newFinally : node.Finally,
      node.Fault,
      newHandlers != null ? newHandlers : newHandlers
    );
  }
  return node;
}

.NET Compiler Platform ("Roslyn")

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value. AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs 177


private Task<SyntaxToken>
GetNewTokenWithRemovedOrToggledPragmaAsync(....)
{
  var result = isStartToken
    ? GetNewTokenWithPragmaUnsuppress(
        token, indexOfTriviaToRemoveOrToggle, _diagnostic, Fixer,
        isStartToken, toggle)
    : GetNewTokenWithPragmaUnsuppress(
        token, indexOfTriviaToRemoveOrToggle, _diagnostic, Fixer,
        isStartToken, toggle);

  return Task.FromResult(result);
}

.NET Compiler Platform ("Roslyn")

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: ScriptingResources.PlusAdditionalError. CommandLineRunner.cs 428


private void DisplayDiagnostics(....)
{
  ....
  _console.Out.WriteLine(
    string.Format((notShown == 1) ?
      ScriptingResources.PlusAdditionalError :
      ScriptingResources.PlusAdditionalError,
      notShown));
  ....
}

Mono

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: Color.FromArgb (150, 179, 225). ProfessionalColorTable.cs 258


private void CalculateColors ()
{
  ....
  button_pressed_highlight = use_system_colors ?
                             Color.FromArgb (150, 179, 225) :
                             Color.FromArgb (150, 179, 225);
  ....
}

RunUO

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: 0xe7f. TreasureChestLevel2.cs 52


private void SetChestAppearance()
{
  bool UseFirstItemId = Utility.RandomBool();

  switch( Utility.RandomList( 0, 1, 2, 3, 4, 5, 6, 7 ) )
  {
    ....
    case 6:// Keg
      this.ItemID = ( UseFirstItemId ? 0xe7f : 0xe7f );
      this.GumpID = 0x3e;
      break;

    case 7:// Barrel
      this.ItemID = ( UseFirstItemId ? 0xe77 : 0xe77 );
      this.GumpID = 0x3e;
      break;
  }
}

Similar errors can be found in some other places:

  • V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: 0xe77. TreasureChestLevel2.cs 57

Garnet

V3012 The '?:' operator, regardless of its conditional expression, always returns one and the same value: TimeSpan.FromMilliseconds(10). FileLoggerProvider.cs 43


public class FileLoggerOutput : IDisposable
{
  private StreamWriter streamWriter;
  private readonly object lockObj = new object();
  private readonly TimeSpan flushInterval =
                                            Debugger.IsAttached ?
                                            TimeSpan.FromMilliseconds(10) :
                                            TimeSpan.FromMilliseconds(10);
  private DateTime lastFlush = DateTime.UtcNow;
  ....
}