# C# 9 new() syntax and private constructors lead to reported code smell/bug

**URL:** <https://community.sonarsource.com/t/c-9-new-syntax-and-private-constructors-lead-to-reported-code-smell-bug/36073>\
**Category:** SonarQube Cloud\
**Tags:** csharp\
**Created:** [December 18, 2020, 2:01pm UTC](https://community.sonarsource.com/t/c-9-new-syntax-and-private-constructors-lead-to-reported-code-smell-bug/36073 "2020-12-18T14:01:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsc\_templafy](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tsc_templafy/32/17820_2.png) [@tsc\_templafy](https://community.sonarsource.com/u/tsc_templafy)\
**Post date:** [December 18, 2020, 2:01pm UTC](https://community.sonarsource.com/t/c-9-new-syntax-and-private-constructors-lead-to-reported-code-smell-bug/36073/1 "2020-12-18T14:01:44Z")

</div>

When using the C# 9 new() syntax ( [Target-typed new](https://github.com/dotnet/csharplang/issues/100)) with private constructors, Sonarcloud reports one of the following issues:

_Code Smell: Remove the unused private constructor Foo_

```
public class Foo
    {
        private Foo()
        {
        }
        public static Foo Create()
        {
            return new();
        }
    }

```

_Bug: This class can’t be instantiated; make its constructor ‘public’._

```
public class Foo
{
    public static readonly Foo Instance = new();
    private Foo()
    {
    }
}
```

---

<div class="post-metadata">

**Author:** ![costin.zaharia](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/costin.zaharia/32/62600_2.png) [@costin.zaharia](https://community.sonarsource.com/u/costin.zaharia)\
**Post date:** [February 2, 2021, 8:07am UTC](https://community.sonarsource.com/t/c-9-new-syntax-and-private-constructors-lead-to-reported-code-smell-bug/36073/2 "2021-02-02T08:07:56Z")

</div>

Hi @tsc_templafy,

and thanks for the feedback.

We are currently aware of this issue (we have a test case documented [here](https://github.com/SonarSource/sonar-dotnet/blob/67985324dc14b5d410f32b6da205433f404a5b35/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/UnusedPrivateMember.CSharp9.cs#L69)) and we do plan to improve our support for the new features added in C# 9 in the following months.

Best,  
Costin
